gpt4 book ai didi

java - Spring-Batch 复合编写器如何跳过异常

转载 作者:行者123 更新时间:2023-12-01 16:19:00 24 4
gpt4 key购买 nike

我正在使用 Spring Batch,我的步骤配置如下:

 @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();
}

我的复合项目编写器


@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;
}


现在,如果 writer1 上出现 DataIntegrityViolationException,我的跳过监听器将在我进行日志记录时被调用,然后控制将转到下一步

我正在寻找一种将控制权交给当前被跳过的下一个编写器的方法

最佳答案

这种类型的编排需要通过您自己的组合 ItemWriter 来完成。 Spring Batch 没有开箱即用的组件来处理此类单个组件逻辑中的异常。

关于java - Spring-Batch 复合编写器如何跳过异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62320057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com