เริ่มต้นอย่างรวดเร็ว
เชื่อมโยง Entity, Handler และ Swagger watcher ตาม backend source และตรวจสอบผลลัพธ์การสร้างครั้งแรก.
การตั้งค่าท้องถิ่นทั้งหมด
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();
}
}การตรวจจับการเปลี่ยนแปลงและการเริ่มต้นครั้งแรก
start() สร้าง watcher instance และดำเนินการ generation pass แรก จากนั้น subscribe ต่อเหตุการณ์การเปลี่ยนแปลง source หลายไฟล์จะถูกจัดกลุ่มตาม debounceMillis และสร้างใหม่