问题
I am using Spring Batch and my step configuration is as below:
@Bean
public Step testStep(
JdbcCursorItemReader<TestStep> testStageDataReader,
TestStepProcessor testStepProcessor,
CompositeItemWriter<Writer> testWriter,
PlatformTransactionManager transactionManager,
JobRepository jobRepository) {
return stepBuilderFactory
.get("TESTING")
.<>chunk(100)
.reader(testStageDataReader)
.processor(testStepProcessor)
.writer(testWriter)
.faultTolerant()
.skip(DataIntegrityViolationException.class)
.skipLimit(1)
.listener(new SkipTestListener())
.transactionManager(transactionManager)
.repository(jobRepository)
.build();
}
My composite item writer
@Bean
public CompositeItemWriter<Writer> testWriter(
Writer1 writer1,
Writer2 writer2,
Writer3 writer3)
throws Exception {
List<ItemWriter<? super Writer>> writers = new ArrayList<>();
writers.add(writer1);
writers.add(writer2);
writers.add(writer3);
CompositeItemWriter<Writer> writers = new CompositeItemWriter<>();
workingWellDailyMemberAggWriter.setDelegates(writers);
workingWellDailyMemberAggWriter.afterPropertiesSet();
return writers;
}
Now, If there is a DataIntegrityViolationException on writer1 my skip listener is invoked where I do my logging and then control goes to next step
What I am looking for a way that control goes to the next writer which are currently get skipped
回答1:
This type of orchestration needs to be done via your own composite ItemWriter. Spring Batch doesn't have an out of the box component that will handle exceptions within the logic of a single component like that.
来源:https://stackoverflow.com/questions/62320057/spring-batch-how-skip-exceptions-works-for-composite-writers