-
Notifications
You must be signed in to change notification settings - Fork 0
Spring Boot Batch
stella edited this page Jun 19, 2014
·
6 revisions
- 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 );
}
}- Job Initialize를 할 수 있도록 프로퍼티 설정
spring.batch.job.enabled=true #default가 true임. - job Name을 지정하지 않으면 등록된 모든 JOB이 실행되므로 주의!!
- main 클래스 실행 시 커맨드라인 파라메터로 job name 지정
--spring.batch.job.names=myJob - 복수개의 JOB도 지정 가능함. (콤마로 구분)
- 커맨드라인 파라메터로 줄 경우 @Value 어노테이션을 통해 사용 가능함
@Value("${date}")
private String date;