문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 다음 판 | 이전 판 | ||
|
springframework:batch:commandlinejobrunner [2018/04/30 12:09] kwon37xi 만듦 |
springframework:batch:commandlinejobrunner [2018/07/24 17:57] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| ====== Spring Batch Command Line Job Runner ====== | ====== Spring Batch Command Line Job Runner ====== | ||
| + | * [[springframework: | ||
| * Spring Batch를 명령행으로 실행할 수 있다. | * Spring Batch를 명령행으로 실행할 수 있다. | ||
| * [[https:// | * [[https:// | ||
| 줄 16: | 줄 17: | ||
| ===== SpringBoot 와 연동 ===== | ===== SpringBoot 와 연동 ===== | ||
| + | |||
| + | 아래 사용하지 말 것. [[springframework: | ||
| + | |||
| + | ------------- | ||
| + | |||
| * [[https:// | * [[https:// | ||
| * Spring Boot와 연동시에는 '' | * Spring Boot와 연동시에는 '' | ||
| 줄 22: | 줄 28: | ||
| bootJar { | bootJar { | ||
| mainClassName = ' | mainClassName = ' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Spring batch Job이 자동시작되는 것을 막고 명시적 실행만 되게 하려면 다음 설정이 '' | ||
| + | |||
| + | <code yml> | ||
| + | spring: | ||
| + | batch: | ||
| + | job: | ||
| + | enabled: false | ||
| + | </ | ||
| + | |||
| + | 이제 Java Config 파일에 Job을 '' | ||
| + | <code java> | ||
| + | @Configuration | ||
| + | @EnableBatchProcessing | ||
| + | public class SpringBatchConfig { | ||
| + | |||
| + | Logger logger = LoggerFactory.getLogger(SpringBatchConfig.class); | ||
| + | |||
| + | @Autowired | ||
| + | public JobBuilderFactory jobBuilderFactory; | ||
| + | |||
| + | @Autowired | ||
| + | public StepBuilderFactory stepBuilderFactory; | ||
| + | |||
| + | @Bean | ||
| + | public Job job1() { | ||
| + | return jobBuilderFactory.get(" | ||
| + | .incrementer(new RunIdIncrementer()) | ||
| + | .start(step1()).build(); | ||
| + | } | ||
| + | |||
| + | private TaskletStep step1() { | ||
| + | Tasklet tasklet = (contribution, | ||
| + | logger.info(" | ||
| + | + context.getStepContext().getJobParameters().get(" | ||
| + | return RepeatStatus.FINISHED; | ||
| + | }; | ||
| + | return stepBuilderFactory.get(" | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| 줄 27: | 줄 74: | ||
| 이제 '' | 이제 '' | ||
| <code sh> | <code sh> | ||
| - | java -jar build/ | + | java -jar build/ |
| + | | ||
| </ | </ | ||