Skip to content
stella edited this page Jun 18, 2014 · 6 revisions

Spring Batch + Boot

  • Batch 수행에 대해 Boot에서 간단하게 처리해 줌. (@EnableBatchProcessing (from Spring Batch))
  • 모든 Job을 실행시키는게 디폴트이지만 특정 JOB을 지정할 수도 있음. (프로퍼티 파일을 통해 지정)

Spring Batch auto configuration is enabled by adding @EnableBatchProcessing (from Spring Batch) somewhere in your context. By default it executes all Jobs in the application context on startup (see JobLauncherCommandLineRunner for details). You can narrow down to a specific job or jobs by specifying spring.batch.job.names (comma separated job name patterns). If the application context includes a JobRegistry then the jobs in spring.batch.job.names are looked up in the registry instead of being autowired from the context. This is a common pattern with more complex systems where multiple jobs are defined in child contexts and registered centrally. See BatchAutoConfiguration and @EnableBatchProcessing for more details.

  • Boot 에서 내부적으로 JobLauncherCommandLineRunner를 생성, 지정한 JOB들을 실행시킨다.
  • Job 구동 환경에 대해 간단하게 설정 가능
@Configuration
@ComponentScan
@EnableBatchProcessing
@EnableAutoConfiguration
public class MelonApplication {
        public static void main( String [] args ) {
               SpringApplication app = new SpringApplication(MelonApplication . class);
               app .run(args );
       }
}
  • 위 main을 실행시킬때 파라메터로 실행시킬 JOB을 지정한다. 콤마(,)로 여러개의 JOB 지정 가능. 그냥 실행할 경우 JobRepository에 등록된 모든 job이 실행되니 주의..!!
--spring.batch.job.names=myjob
  • 실행결과 로그 --> 샘플이라서 job이 없어서 수행하지 않는다.
[INFO  ] 2014-06-18 11:49:25 JobLauncherCommandLineRunner - Running default command line with: [--spring.batch.job.names=myjob]
[DEBUG] 2014-06-18 11:49:25 JobLauncherCommandLineRunner - No job found in registry for job name: myjob
  • Boot와 Batch로 같이 구성할 경우 이런식으로 실행시키는게 맞는지 아직 레퍼런스가 부족...

Clone this wiki locally