简体   繁体   中英

Spring-Batch How skip exceptions works for composite writers

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM