Skippable exception classes for Spring Batch with

2020-06-03 00:59发布

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

2条回答
2楼-- · 2020-06-03 01:55
@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() 
}
查看更多
你好瞎i
3楼-- · 2020-06-03 01:56

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

return stepBuilder()
  .chunk()
  .faultTolerant()
  .skip(MyException.class)
  .skipLimit(100000)
.build()
查看更多
登录 后发表回答