简体   繁体   English

具有基于Java的配置的Spring Batch的可跳过异常类

[英]Skippable exception classes for Spring Batch with java based configuration

I configure a step in XML like this: 我在XML中配置一个步骤,如下所示:

<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: 在java配置中,我使用这样的StepBuilder:

@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 但我找不到配置可跳过的异常类的方法

You need to build up a FaultTolerantStepBuilder using StepBuilder.faultTolerant method. 你需要建立一个FaultTolerantStepBuilder使用StepBuilder.faultTolerant方法。

return stepBuilder()
  .chunk()
  .faultTolerant()
  .skip(MyException.class)
  .skipLimit(100000)
.build()
@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() 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM