Bắt đầu nhanh
Kết nối backend source với Entity, Handler và Swagger watcher, và kiểm tra kết quả tạo ban đầu.
Cấu hình cục bộ tổng thể
WatchForMainRunSpring.java
java@Configuration
@Profile("local")
public class WatchForMainRunSpring {
private WatchForMainRun runner;
@PostConstruct
public void start() {
var entityConfig = EntityFileWatcher.Config.builder()
.rootPath("src.main.java")
.entityPackage("com.example.entity")
.fieldPackage("com.example.util.fields")
.collectionNamePackage("com.example.util")
.build();
var handlerConfig = HandlerGenerator.Config.builder()
.rootPath("src.main.java")
.routerPackage("com.example.web.router")
.handlerOutputDir("src.main.java.com.example.web.handler")
.addAutoImport(ReactiveMongoDsl.class)
.addAutoImport(ResponseWrapper.class)
.addStaticAutoImport(
HandlerGenerator.StaticImportSpec.of(ResponseWrapper.class, "response")
)
.addStaticAutoImport(
HandlerGenerator.StaticImportSpec.of(FieldsPair.class, "pair")
)
.build();
var swaggerConfig = SwaggerJsonFileWatcher.Config.builder()
.watchDirectory("src/main/java")
.swaggerOutputFile("src/main/resources/static/swagger.json")
.build();
runner = new WatchForMainRun(
WatchForMainRun.Config.builder()
.debounceMillis(400)
.entityConfig(entityConfig)
.handlerConfig(handlerConfig)
.swaggerConfig(swaggerConfig)
.build()
);
try {
runner.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start development watchers", e);
}
}
@PreDestroy
public void stop() {
if (runner != null) runner.stop();
}
}Phát hiện thay đổi và thực thi lần đầu
start() tạo instance watcher và thực hiện lần tạo đầu tiên, sau đó đăng ký sự kiện thay đổi nguồn. Nhiều sự kiện tệp sẽ được nhóm lại theo tiêu chí debounceMillis và tạo lại.