Spring Batch的可跳过异常类,基于java的配置 [英] Skippable exception classes for Spring Batch with java based configuration

查看:85
本文介绍了Spring Batch的可跳过异常类,基于java的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML中配置一个步骤:

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>

在java配置中,我使用这样的StepBuilder:

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

推荐答案

您需要使用 StepBuilder构建 FaultTolerantStepBuilder .faultTolerant 方法。

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

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

这篇关于Spring Batch的可跳过异常类,基于java的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆