Inflearn brand logo image

인프런 커뮤니티 질문&답변

02 aruarian님의 프로필 이미지
02 aruarian

작성한 질문수

[스프링 배치 입문] 예제로 배우는 핵심 Spring Batch

일단 실행 - Hello, World (스프링 배치 구조 익히기)

spring batch 5.x 버전 설정

작성

·

49

1

@SpringBootApplication
class SpringBatchTutorialApplication

fun main(args: Array<String>) {
    runApplication<SpringBatchTutorialApplication>(*args)
}

@EnableBatchProcessing 은 3.x 부터 사용하지 않습니다.

 

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/batchex
    username: root
    password: root123
  batch:
    job:
      names: ${job.name=NONE}
      enabled: true
    jdbc:
      initialize-schema: always
  jpa:
    show-sql: true


logging:
  level:
    org.springframework.batch: DEBUG

 

@Configuration
class HelloWorldJobConfig(
    private val jobRepository: JobRepository,
    private val platformTransactionManager: PlatformTransactionManager,
) {

    @Bean
    fun helloWorldJob(): Job = JobBuilder("helloWorldJob", jobRepository)
            .incrementer(RunIdIncrementer())
            .start(helloWorldStep())
            .build()

    @JobScope
    @Bean
    fun helloWorldStep() = StepBuilder("helloWorldStep", jobRepository)
        .tasklet(helloWorldTasklet(), platformTransactionManager)
        .build()

    @StepScope
    @Bean
    fun helloWorldTasklet(): Tasklet = Tasklet { contribution, context ->
        println("Hello, World from Kotlin Tasklet!")
        println("Hello, World from Kotlin Tasklet!")
        println("Hello, World from Kotlin Tasklet!")
        RepeatStatus.FINISHED
    }

}

 

program arguments 설정하고 실행하면 잘 될겁니다.

답변 2

0

감사합니다 @EnableBatchProcessing 제거하니 되네요!!

0

안녕하세요, 인프런 AI 인턴입니다.

@EnableBatchProcessing을 3.x 버전부터 사용하지 않는 대신, BatchAutoConfiguration 및 자동 설정된 환경에서 사용할 수 있는 JobBuilderFactoryStepBuilderFactory를 활용할 수 있습니다. 현재 주어진 Spring Batch 설정은 잘 구성된 것으로 보입니다.

특히, Spring Boot와 Spring Batch의 설정을 맞추어 주시고 JobRepositoryPlatformTransactionManager를 생성자 주입 방식으로 사용하고 있습니다. 이렇게 하면 컨텍스트가 올바르게 설정되고, 각 작업 및 단계를 구성할 수 있습니다. Spring Batch 5.x 버전에서 프로그램 아규먼트를 설정하고 실행하면 예상대로 작동할 것입니다.

데이터베이스 설정, Job 및 Step 설정, 그리고 로깅 레벨 설정도 명확합니다. 추가로 사용자가 언급한 데이터 소스 및 Job 실행 설정도 올바르며, Spring Batch의 job 이름과 실행 가능 옵션을 명시적으로 설정하여 원하는 작업이 올바르게 수행될 것입니다.

만약 실행 도중 문제가 발생한다면, 설정된 로깅 레벨을 통해 디버깅 정보를 확인하실 수 있습니다. Spring Batch 및 관련 설정에 대한 자세한 내용은 다음 링크에서 참고할 수 있다는 점 기억해 주세요: Spring Batch project page.

질문해 주셔서 감사합니다, 02 aruarian님. 다른 질문이 있으시면 언제든지 문의해 주세요.

02 aruarian님의 프로필 이미지
02 aruarian

작성한 질문수

질문하기