문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
springframework:batch [2018/09/17 17:19] kwon37xi |
springframework:batch [2019/12/03 14:10] kwon37xi |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Spring Framework Batch ====== | ====== Spring Framework Batch ====== | ||
* [[springframework: | * [[springframework: | ||
- | * [[http:// | ||
- | * [[https:// | ||
- | * [[http:// | ||
- | * [[https:// | ||
- | * Spring Batch 2.2 JavaConfig | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * Spring Batch Transaction | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[http:// | ||
===== @EnableBatchProcessing ===== | ===== @EnableBatchProcessing ===== | ||
줄 55: | 줄 28: | ||
</ | </ | ||
* '' | * '' | ||
+ | * SpringBoot 에서 '' | ||
===== JobRepository ===== | ===== JobRepository ===== | ||
줄 70: | 줄 44: | ||
===== Transaction 설정 ===== | ===== Transaction 설정 ===== | ||
- | ===== 트랜잭션 매니저를 지정하지 않으면 | + | ==== 트랜잭션 매니저를 지정하지 않으면 ==== |
TransactionManager를 지정하지 않으면 다음과 같은 오류가 발생한다. | TransactionManager를 지정하지 않으면 다음과 같은 오류가 발생한다. | ||
줄 103: | 줄 77: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ==== Chunk 사이즈가 크고 Transaction 이 긴데, 외부에 write 대상건을 알려주는 경우 DB Lock 발생할 수 있음 ==== | ||
+ | * batch 에 트랜잭션 매니저를 설정하고, | ||
+ | * 외부에서 그 데이터를 사용할 수 있게 하고자 했다면, | ||
+ | * 절대로 Step 에 트랜잭션 매니저를 지정하지 말고, '' | ||
+ | * 안그러면 CHUNK size 만큼의 처리가 모두 끝날때까지 DB lock 이 잡혀있어서 외부에서 이벤트를 받아서 처리하는 측에서 lock 획득에 실패해서 오류가 발생하게 된다. | ||
===== JobInstanceAlreadyCompleteException: | ===== JobInstanceAlreadyCompleteException: | ||
줄 116: | 줄 96: | ||
.build(); | .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, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Java Config Spring Bean 설정시 리턴 타입을 인터페이스가 아닌 구현 클래스로 지정할 것. ===== | ||
+ | * '' | ||
+ | * 따라서 Spring Batch 용 각 스텝별 Bean 을 생성해서 리턴할 때는 항상 **구현 클래스를 리턴 타입으로 지정**할 것. | ||
+ | * [[https:// | ||
+ | * 다음과 같은 WARN 을 볼 수도 있다. | ||
+ | |||
+ | > o.s.b.c.l.AbstractListenerFactoryBean | ||
+ | |||
+ | |||
+ | ===== Test ===== | ||
+ | * [[https:// | ||
+ | * 이 클래스는 static utility 가 아니라 Bean 으로 생성해줘야 하는 것이다. | ||
+ | * '' | ||
+ | * 특정 Step만 테스트도 가능함. | ||
+ | * [[springframework: | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | |||
===== 참고 ===== | ===== 참고 ===== | ||
- | * [[https:// | + | |
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * Spring Batch 2.2 JavaConfig | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * Spring Batch Transaction | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// |