사용자 도구

사이트 도구


springframework:batch

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
springframework:batch [2018/09/15 20:58]
kwon37xi
springframework:batch [2019/02/25 19:19]
kwon37xi
줄 2: 줄 2:
   * [[springframework:springboot:batch|SpringBoot와 SpringBatch]]   * [[springframework:springboot:batch|SpringBoot와 SpringBatch]]
   * [[http://www.javaworld.com/article/2458888/spring-framework/open-source-java-projects-spring-batch.html|Open source Java projects: Spring Batch]] : SpringBatch 2.x의 기본 적인 Tasklet, chunk, reader/writer/processor, retry 등의 개념 들을 예제와 함께 설명하고 있음.   * [[http://www.javaworld.com/article/2458888/spring-framework/open-source-java-projects-spring-batch.html|Open source Java projects: Spring Batch]] : SpringBatch 2.x의 기본 적인 Tasklet, chunk, reader/writer/processor, retry 등의 개념 들을 예제와 함께 설명하고 있음.
 +  * [[https://www.javacodegeeks.com/2015/03/spring-batch-tutorial.html|Spring Batch Tutorial – The ULTIMATE Guide]]
   * [[http://www.mkyong.com/tutorials/spring-batch-tutorial/|Spring Batch Tutorial]] : 매우 상세한 튜토리얼   * [[http://www.mkyong.com/tutorials/spring-batch-tutorial/|Spring Batch Tutorial]] : 매우 상세한 튜토리얼
   * [[https://www.tutorialspoint.com/spring_batch/spring_batch_environment.htm|Spring Batch Environment]]   * [[https://www.tutorialspoint.com/spring_batch/spring_batch_environment.htm|Spring Batch Environment]]
줄 27: 줄 28:
   * [[https://examples.javacodegeeks.com/enterprise-java/java-batch-tutorial/|Java Batch Tutorial | Examples Java Code Geeks - 2018]]   * [[https://examples.javacodegeeks.com/enterprise-java/java-batch-tutorial/|Java Batch Tutorial | Examples Java Code Geeks - 2018]]
   * [[http://opennote46.tistory.com/76|Spring Batch - 작업실행]]   * [[http://opennote46.tistory.com/76|Spring Batch - 작업실행]]
 +  * [[https://grokonez.com/spring-framework/spring-batch/use-spring-batch-late-binding-step-scope-job-scope|How to use Spring Batch Late Binding - Step Scope & Job Scope - grokonez]]
 +  * [[https://grokonez.com/spring-framework-tutorial/spring-batch|Spring Batch - grokonez]]
 +  * [[https://www.mkyong.com/spring-batch/spring-batch-example-mysql-database-to-xml/|Spring Batch Example – MySQL Database To XML – Mkyong.com]]
 +  * [[https://examples.javacodegeeks.com/enterprise-java/spring/batch/spring-batch-exception-handling-example/|Spring Batch Exception Handling Example | Examples Java Code Geeks - 2018]]
 +  * [[http://www.egovframe.go.kr/wiki/doku.php?id=egovframework:rte2:brte:batch_core:parallel_process|egovframework:rte2:brte:batch_core:parallel_process [eGovFrame]]]
 +
  
 ===== @EnableBatchProcessing ===== ===== @EnableBatchProcessing =====
줄 54: 줄 61:
 </code> </code>
   * ''dataSource'' 자체를 null로 지정하면 ''MapJobRepository''로 DB없이 작동하게 만들어진다.   * ''dataSource'' 자체를 null로 지정하면 ''MapJobRepository''로 DB없이 작동하게 만들어진다.
 +  * SpringBoot 에서 ''DefaultBatchConfigurer'' 사용시 TransactionManager 오작동 문제가 발생한다. [[springframework:springboot:batch|SpringBoot와 SpringBatch]] 참고
 ===== JobRepository ===== ===== JobRepository =====
   * ''org.springframework.batch.core.repository.support.JobRepositoryFactoryBean''로 ''SimpleJobRepository'' 생성   * ''org.springframework.batch.core.repository.support.JobRepositoryFactoryBean''로 ''SimpleJobRepository'' 생성
줄 116: 줄 123:
 </code> </code>
  
 +===== RunIdIncrementer 사용시 기존 파라미터가 현재 파라미터 지정한 것을 덮어씀  =====
 +  * ''RunIdIncrementer''를 사용하게 되면 항상 기존 실행됐던 Job의 파라미터가 현재 파라미터를 덮어쓰는 현상이 발생한다.
 +  * 이유는 ''RunIdIncrementer''가 동일 파라미터로 Job을 실행하려고 사용하는 것이라서 인 듯 하다.
 +  * 따라서 ''RunIdIncrementer''를 사용하면서도 파라미터를 유지하려면 다른 방식을 써야 한다.
 +  * [[https://github.com/codecentric/spring-boot-starter-batch-web/issues/38|optional/omitted jobParameters are reloaded from previous jobs · Issue #38 · codecentric/spring-boot-starter-batch-web]]
 +
 +<code java>
 +/**
 + * 파라미터를 복사하지 않는 RunIdIncrementer
 + */
 +public class ParamCleanRunIdIncrementer implements JobParametersIncrementer {
 +    private static String RUN_ID_KEY = "run.id";
 +    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, 0L) + 1;
 +        return new JobParametersBuilder().addLong(key, id).toJobParameters(); // 이부분이 RunIdIncrementer와 다르다.
 +    }
 +}
 +</code>
  
 +===== Test =====
 +  * [[https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/test/JobLauncherTestUtils.html|JobLauncherTestUtils]]로 테스트 가능. 
 +    * 이 클래스는 static utility 가 아니라 Bean 으로 생성해줘야 하는 것이다.
 +    * ''setJob()''으로 특정 Job을 지정하거나, 그냥 ''@Autowired''될 수도 있음.
 +    * 특정 Step만 테스트도 가능함.
 +  * [[springframework:springboot:batch|SpringBoot와 SpringBatch]] 시에는 ''@MockBean''도 가능.
 +  * [[https://www.mkyong.com/spring-batch/spring-batch-unit-test-example/|Spring Batch unit test example – Mkyong.com]]
 +  * [[http://hwannnn.blogspot.com/2018/06/spring-batch-test-joblaunchertestutils_5.html|JobLauncherTestUtils를 이용한 Spring Batch Test]]
  
 +===== 참고 =====
 +  * [[https://dzone.com/articles/spring-batch-with-quartz|Run a Spring Batch Job With Quartz]]
 +  * [[https://www.youtube.com/watch?v=CYTj5YT7CZU&feature=youtu.be|Spring Batch (Michael Minella) - YouTube]]
springframework/batch.txt · 마지막으로 수정됨: 2023/12/08 13:43 저자 kwon37xi