0

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

JDev
  • 1,662
  • 4
  • 25
  • 55
  • don't throw an Exception. catch it and throw an object. But, if an error occurs during the processing of an item, the batch should go to the next item to process. – Stultuske Jun 11 '20 at 08:22
  • I have 3 writers that get called in sequential order. If there is an exception happens at writer 1, I want my writer 2 and 3 to be called. Right now, If I have 1 record and exception occurs then writer 2 and 3 are not called. – JDev Jun 11 '20 at 22:18
  • ok. so extract those writers into a separate process. or add all the writing business logic into one single writer. – Stultuske Jun 12 '20 at 06:12

1 Answers1

0

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.

Michael Minella
  • 20,843
  • 4
  • 55
  • 67
  • Could you please share more code details here? Please guide here too: https://stackoverflow.com/questions/63296065/how-to-override-spring-batch-compositeitemwriter-manage-transaction-for-delegate – Jeff Cook Aug 07 '20 at 06:05