❐ 1. Chaining itemProcessor
- ItemProcessor로 부가적인 로직을 짤 수 있음.
- 근데 ItemProcessor를 체이닝을 걸어서 쓰고 싶다면?
@Configuration
class BatchConfig {
@Bean
fun ioSampleJob(jobRepository: JobRepository, step1: Step): Job =
JobBuilder("ioSampleJob", jobRepository)
.start(step1)
.build()
@Bean
fun step1(
jobRepository: JobRepository,
transactionManager: PlatformTransactionManager
): Step =
StepBuilder("step1", jobRepository)
.chunk<Any, Any>(2, transactionManager)
.reader(fooReader())
.processor(compositeProcessor())
.writer(foobarWriter())
.build()
@Bean
fun compositeProcessor(): CompositeItemProcessor<Any, Any> =
CompositeItemProcessor<Any, Any>().apply {
setDelegates(listOf(FooProcessor(), BarProcessor()))
}
// 아래 메서드/클래스들은 실제 구현에 맞게 정의되어 있어야 합니다.
fun fooReader() = /* ItemReader<Any> */ TODO()
fun foobarWriter() = /* ItemWriter<Any> */ TODO()
class FooProcessor : ItemProcessor<Any, Any> {
override fun process(item: Any): Any? = /* transform */ item
}
class BarProcessor : ItemProcessor<Any, Any> {
override fun process(item: Any): Any? = /* transform */ item
}
}
나머지는 읽어보면 될듯.
'Book > Spring Batch docs' 카테고리의 다른 글
| Retry (0) | 2025.10.10 |
|---|---|
| Scaling and Parallel Processing (0) | 2025.10.10 |
| ItemReaders and ItemWriters (0) | 2025.10.07 |
| Configuring a Step (0) | 2025.10.06 |
| Configuring and Running a Job (0) | 2025.07.17 |