Spring-Batch跳过异常如何为复合编写器工作 [英] Spring-Batch How skip exceptions works for composite writers

查看:159
本文介绍了Spring-Batch跳过异常如何为复合编写器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的复合物品作家


 @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,则会在我进行日志记录的地方调用我的跳过侦听器,然后然后控制转到下一步

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

推荐答案

这种编排需要通过您自己的复合ItemWriter完成. Spring Batch没有一个开箱即用的组件,可以处理像这样的单个组件的逻辑内的异常.

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.

这篇关于Spring-Batch跳过异常如何为复合编写器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆