12

I configure a step in XML like this:

<batch:step id="slaveStep">
        <batch:tasklet>
            <batch:chunk
                    reader="reader"
                    processor="processor"
                    writer="writer"
                    commit-interval="10"
                    skip-limit="100000">
                <batch:skippable-exception-classes>
                    <batch:include class="MyException"/>
                </batch:skippable-exception-classes>
            </batch:chunk>
        </batch:tasklet>
    </batch:step>

In the java configuration I use a StepBuilder like this:

@Bean
public StepBuilder stepBuilder(String stepName)
{
    return new StepBuilder(stepName);
}

@Bean
Step slaveStep()
{
    return stepBuilder("slaveStep")
            .<Movie, Movie>chunk(10)
            .reader(reader(new HashMap<>()))
            .processor(processor())
            .writer(writer())
            .build();
}

But I could not find a way to configure the skippable exception classes

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Amer A.
  • 1,025
  • 2
  • 16
  • 22

2 Answers2

24

You need to build up a FaultTolerantStepBuilder using StepBuilder.faultTolerant method.

return stepBuilder()
  .chunk()
  .faultTolerant()
  .skip(MyException.class)
  .skipLimit(100000)
.build()
Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • Thanks for this. Could you point me to where is that information listed? I've searched for it in spring docs and couldn't find any mention of it. – Cristiano Fontes Aug 03 '15 at 16:05
  • 2
    see at http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/step/builder/StepBuilder.html#chunk-org.springframework.batch.repeat.CompletionPolicy- and http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/step/builder/SimpleStepBuilder.html#faultTolerant--. But honestly I found this method while I was looking at SB code – Luca Basso Ricci Aug 03 '15 at 19:45
3
@Configuration
@EnableBatchProcessing
@Import(DataConfig.class)
    public class SpringBatchConfig {
    ..................
    ..................
    @Autowired
    private StepBuilderFactory stepBuilders;

    @Bean
    public Step loadSlaveStep()
        return stepBuilders.get("slaveStep")()
       .chunk()
       .faultTolerant()
       .skip(MyException.class)
       .skipLimit(100000)
       .build() 
}
Mahesh
  • 954
  • 8
  • 18