Spring Batch 5

<aside> 💡 Spring Batch 5는 최소 버전으로 Java 17이 필요한 Spring Framework 6을 기반 https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#dependencies-upgrade

</aside>

1. build.gradle


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-batch'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation'org.springframework.boot:spring-boot-starter-quartz'
    implementation 'org.postgresql:postgresql:42.7.2'

    runtimeOnly 'org.postgresql:postgresql'

    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    testImplementation platform('org.junit:junit-bom:5.9.1')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

2. application.yml

spring:
  main:
    allow-bean-definition-overriding: true
  batch:
    job:
      enabled: true # 서버 재시작시 배치 자동실행 방지 = false
      jdbc:
        initialize-schema: always 
  quartz:
    job-store-type: jdbc
    jdbc:
      initialize-schema: always 
 # DB ...

3. Main

//@EnableBatchProcessing  //  배치 기능 활성 spring 3.0 이상은 사용하지 않는다 기본 설정이 백오프 된다.
@EnableScheduling  //Spring scheduler
@SpringBootApplication
public class BatchTestApplication {
    public static void main(String[] args) {
        SpringApplication.run(BatchTestApplication.class, args);
    }
}

4. Job.java

Untitled

Job - 처리하고자 하는 작업 단위