Spring/Spring Batch
스프링 부트 5.0 JobBuilderFactory, StepBuilderFactory Deprecated
마늘냄새폴폴
2023. 5. 30. 13:29
스프링 부트가 5.0에 들어오면서 기존 Job과 Step을 작성할 때 사용하던 JobBuilderFactory, StepBuilderFactory가 Deprecated 되었습니다.
때문에 기존 방법 대신 아래와 같은 방법으로 사용해야합니다.
@Configuration
@RequiredArgsConstructor
@Slf4j
public class MonthClickToZeroBatch {
private final EntityManagerFactory emf;
private final JobRepository jobRepository;
private final PlatformTransactionManager platformTransactionManager;
private static final int PAGE_SIZE = 1000;
@Bean
public Job clickToZeroBatchJob() {
return new JobBuilder("MonthClickToZeroBatchJob")
.repository(jobRepository)
.incrementer(new UniqueRunIdIncrementer())
.start(clickToZeroBatchStep())
.build();
}
@Bean
public Step clickToZeroBatchStep() {
return new StepBuilder("MonthClickToZeroBatchStep", jobRepository)
.<Item, Item>chunk(PAGE_SIZE, platformTransactionManager)
.reader(itemReader())
.processor(itemProcessor())
.writer(jdbcBatchItemWriter())
.allowStartIfComplete(true)
.build();
}
또한 chunk(int pageSize) 메서드도 Deprecated 되었습니다.
때문에 PlatformTransactionManager를 주입받아서 사용하시면 됩니다.
p.s 근데 5.2에 JobBuilder도 Deprecated 됐는데 어쩌라는거지..