사용자 도구

사이트 도구


springframework:batch

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
springframework:batch [2018/07/04 16:25]
kwon37xi [Java Config]
springframework:batch [2018/09/17 17:19]
kwon37xi
줄 1: 줄 1:
 ====== Spring Framework Batch ====== ====== Spring Framework Batch ======
 +  * [[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]]
   * Spring Batch 2.2 JavaConfig   * Spring Batch 2.2 JavaConfig
     * [[https://blog.codecentric.de/en/2013/06/spring-batch-2-2-javaconfig-part-1-a-comparison-to-xml/|Spring Batch 2.2 - JavaConfig Part 1: A comparison to XML]]     * [[https://blog.codecentric.de/en/2013/06/spring-batch-2-2-javaconfig-part-1-a-comparison-to-xml/|Spring Batch 2.2 - JavaConfig Part 1: A comparison to XML]]
줄 25: 줄 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 - 작업실행]]
 +
 +===== @EnableBatchProcessing =====
 +  * [[https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.html|@EnableBatchProcessing]]을 통해 기본 배치 설정을 수행한다.
 +
 +==== DefaultBatchConfigurer ====
 +  * 설정 중 일부를 Override하고자 한다면 [[https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.html|DefaultBatchConfigurer]] 를 Configuration class에서 상속해서 메소드를 오버라이드 한다.
 +  * ''dataSource'' 오버라이드 예<code java>
 +// 다른 configuration class 에서 DataSource 생성 - embedded 예제
 +@Bean
 +public DataSource batchDataSource() {
 +    return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
 +            .addScript("classpath:/org/springframework/batch/core/schema-h2.sql")
 +            .build();
 +}
 +
 +@EnableBatchProcessing
 +@Configuration
 +public class BatchApplication extends DefaultBatchConfigurer {
 +    // dataSource 설정부분 override. transactionManager도 자동으로 생성함.
 +    @Autowired
 +    @Override
 +    public void setDataSource(@Qualifier("batchDataSource") DataSource batchDataSource) {
 +        super.setDataSource(batchDataSource);
 +    }
 +}
 +</code>
 +  * ''dataSource'' 자체를 null로 지정하면 ''MapJobRepository''로 DB없이 작동하게 만들어진다.
 +
 ===== JobRepository ===== ===== JobRepository =====
   * ''org.springframework.batch.core.repository.support.JobRepositoryFactoryBean''로 ''SimpleJobRepository'' 생성   * ''org.springframework.batch.core.repository.support.JobRepositoryFactoryBean''로 ''SimpleJobRepository'' 생성
줄 32: 줄 63:
     * ''text'' -> ''longtext''     * ''text'' -> ''longtext''
     * ''datetime'' -> ''datetime(6)''로 변경해서 실행할 것.     * ''datetime'' -> ''datetime(6)''로 변경해서 실행할 것.
 +
 ===== Migration ===== ===== Migration =====
   * [[https://harinathreddyyanamala.wordpress.com/2015/02/26/spring-batch-upgrade-from-2-1-7-to-2-2-7/|Spring batch upgrade from 2.1 to 2.2]]   * [[https://harinathreddyyanamala.wordpress.com/2015/02/26/spring-batch-upgrade-from-2-1-7-to-2-2-7/|Spring batch upgrade from 2.1 to 2.2]]
줄 72: 줄 104:
 </code> </code>
  
 +===== JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters 오류 발생 =====
 +  * Job은 Job + Job Parameter 로 Job Key 가 결정되는데 동일한 Job Key 일 경우 실행이 안된다.
 +  * 따라서 Job Parameter를 다는 값으로 주거나 [[https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/launch/support/RunIdIncrementer.html|RunIdIncrementer]]를 사용한다.
 +  * [[https://stackoverflow.com/questions/22148117/spring-batch-error-a-job-instance-already-exists-and-runidincrementer-generate|Spring Batch error (A Job Instance Already Exists) and RunIdIncrementer generates only once]]
 +  * SpringBoot Batch 는 ''RunIdIncrementer''의 특정 파라미터(''run.id'') 값을 계속 증가시켜준다.
 +<code java>
 +jobBuilderFactory.get("myJobName")
 +            .start(step())
 +            . .....
 +            .incrementer(new RunIdIncrementer())
 +            .build();
 +</code>
 +
 +===== 참고 =====
 + * [[https://dzone.com/articles/spring-batch-with-quartz|Run a Spring Batch Job With Quartz]]
springframework/batch.txt · 마지막으로 수정됨: 2023/12/08 13:43 저자 kwon37xi