Quick Start

백엔드 source를 기준으로 Entity, Handler와 Swagger watcher를 연결하고 최초 생성 결과를 확인합니다.


전체 local 설정

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를 실행한 뒤 source change event를 subscribe합니다. 여러 파일 이벤트는 debounceMillis 기준으로 묶어 다시 생성합니다.

다음 문서

© 2026 Byeolnaerim. All rights reserved.소개개인정보처리방침