문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
springframework:batch [2018/05/31 14:01] kwon37xi |
springframework:batch [2019/02/25 19:19] kwon37xi |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Spring Framework Batch ====== | ====== Spring Framework Batch ====== | ||
+ | * [[springframework: | ||
* [[http:// | * [[http:// | ||
+ | * [[https:// | ||
* [[http:// | * [[http:// | ||
+ | * [[https:// | ||
* Spring Batch 2.2 JavaConfig | * Spring Batch 2.2 JavaConfig | ||
* [[https:// | * [[https:// | ||
줄 23: | 줄 26: | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | |||
+ | ===== @EnableBatchProcessing ===== | ||
+ | * [[https:// | ||
+ | |||
+ | ==== DefaultBatchConfigurer ==== | ||
+ | * 설정 중 일부를 Override하고자 한다면 [[https:// | ||
+ | * '' | ||
+ | // 다른 configuration class 에서 DataSource 생성 - embedded 예제 | ||
+ | @Bean | ||
+ | public DataSource batchDataSource() { | ||
+ | return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) | ||
+ | .addScript(" | ||
+ | .build(); | ||
+ | } | ||
+ | |||
+ | @EnableBatchProcessing | ||
+ | @Configuration | ||
+ | public class BatchApplication extends DefaultBatchConfigurer { | ||
+ | // dataSource 설정부분 override. transactionManager도 자동으로 생성함. | ||
+ | @Autowired | ||
+ | @Override | ||
+ | public void setDataSource(@Qualifier(" | ||
+ | super.setDataSource(batchDataSource); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | * '' | ||
+ | * SpringBoot 에서 '' | ||
===== JobRepository ===== | ===== JobRepository ===== | ||
* '' | * '' | ||
줄 31: | 줄 69: | ||
* '' | * '' | ||
* '' | * '' | ||
+ | |||
===== Migration ===== | ===== Migration ===== | ||
* [[https:// | * [[https:// | ||
줄 59: | 줄 98: | ||
</ | </ | ||
+ | ==== Java Config ==== | ||
+ | * Step 등을 생성할 때 '' | ||
+ | |||
+ | <code java> | ||
+ | @Bean | ||
+ | @JobScope | ||
+ | public Step myStep(@Value("# | ||
+ | @Value("# | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== JobInstanceAlreadyCompleteException: | ||
+ | * Job은 Job + Job Parameter 로 Job Key 가 결정되는데 동일한 Job Key 일 경우 실행이 안된다. | ||
+ | * 따라서 Job Parameter를 다는 값으로 주거나 [[https:// | ||
+ | * [[https:// | ||
+ | * SpringBoot Batch 는 '' | ||
+ | <code java> | ||
+ | jobBuilderFactory.get(" | ||
+ | .start(step()) | ||
+ | . ..... | ||
+ | .incrementer(new RunIdIncrementer()) | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | ===== RunIdIncrementer 사용시 기존 파라미터가 현재 파라미터 지정한 것을 덮어씀 | ||
+ | * '' | ||
+ | * 이유는 '' | ||
+ | * 따라서 '' | ||
+ | * [[https:// | ||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * 파라미터를 복사하지 않는 RunIdIncrementer | ||
+ | */ | ||
+ | public class ParamCleanRunIdIncrementer implements JobParametersIncrementer { | ||
+ | private static String RUN_ID_KEY = " | ||
+ | private String key = RUN_ID_KEY; | ||
+ | |||
+ | public void setKey(String key) { this.key = key; } | ||
+ | |||
+ | @Override | ||
+ | public JobParameters getNext(JobParameters parameters) { | ||
+ | JobParameters params = (parameters == null) ? new JobParameters() : parameters; | ||
+ | long id = params.getLong(key, | ||
+ | return new JobParametersBuilder().addLong(key, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Test ===== | ||
+ | * [[https:// | ||
+ | * 이 클래스는 static utility 가 아니라 Bean 으로 생성해줘야 하는 것이다. | ||
+ | * '' | ||
+ | * 특정 Step만 테스트도 가능함. | ||
+ | * [[springframework: | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | ===== 참고 ===== | ||
+ | * [[https:// | ||
+ | * [[https:// |