0

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

我正在寻找一种将控制权转移到当前被跳过的下一个作家的方式

4

1 回答 1

0

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

于 2020-06-15T13:58:33.117 回答