What is the java config equivalent of <no-rollback-exception-classes> tag in spring batch?

614 Views Asked by At

I want java config of below :

`

<step id="step1">
   <tasklet>
      <chunk reader="itemReader" writer="itemWriter" commit-interval="2"/>
      <no-rollback-exception-classes>
         <include class="org.springframework.batch.item.validator.ValidationException"/>
      </no-rollback-exception-classes>
   </tasklet>
</step>

`

<no-rollback-exception-classes> in particular.

Thanks!!!

1

There are 1 best solutions below

0
Mahmoud Ben Hassine On BEST ANSWER

The equivalent to no-rollback-exception-classes in Java config is the org.springframework.batch.core.step.builder.FaultTolerantStepBuilder#noRollback method.

In your case, it would be something like:

@Bean
public Step step(StepBuilderFactory stepBuilderFactory, ItemReader<Integer> itemReader, ItemWriter<Integer> itemWriter) {
    return stepBuilderFactory.get("step1")
            .<Integer, Integer>chunk(2) // TODO change Integer with your item type
            .reader(itemReader)
            .writer(itemWriter)
            .faultTolerant()
            .noRollback(org.springframework.batch.item.validator.ValidationException.class)
            .build();
}

Hope this helps.