Skippable exception classes for Spring Batch with java based configuration

Amer A. picture Amer A. · Jun 15, 2014 · Viewed 10.3k times · Source

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

Answer

Luca Basso Ricci picture Luca Basso Ricci · Jun 16, 2014

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

return stepBuilder()
  .chunk()
  .faultTolerant()
  .skip(MyException.class)
  .skipLimit(100000)
.build()