小编Vin*_*nay的帖子

如果出现自定义异常,请设置步骤执行状态(ABANDONED 除外)

我遇到的情况是步骤可以抛出自定义异常并且作业的执行因异常而停止。我面临的问题是,在“step2”中出现异常时,Spring Batch 设置步骤状态“ABANDONED”,我尝试通过 afterStep 方法覆盖步骤状态,并通过在 afterStep 方法中显式声明可用的 SetpExecution 实例的状态。但是,在数据库表中,步骤“step2”的状态为“已放弃”。我需要将其设置为完成,以便我可以重新启动作业并重新运行该步骤。有什么帮助吗?

下面是作业配置。

<batch:job id="TestJob" job-repository="jobRepository">
    <batch:step id="Step1">
        <tasklet ref="ValidatorTasklet" allow-start-if-complete="true" />
        <!-- <batch:end on="*" /> -->
        <batch:next on="*" to="step2" />
        <batch:next on="FAILED" to="sendErrorEmail" />
    </batch:step>

    <batch:step id="step2">
        <batch:tasklet transaction-manager="hibernateTransactionManager"
            allow-start-if-complete="true">
            <batch:chunk reader="HeaderReader" processor="HeaderProcessor"
                writer="hibernateItemWriter" commit-interval="1" />
        </batch:tasklet>
        <!-- <batch:end on="*" /> -->
        <batch:next on="*" to="step3" />
        <batch:next on="FAILED" to="sendErrorEmail" />
    </batch:step>

    <batch:step id="step3">
        <batch:tasklet transaction-manager="hibernateTransactionManager"
            allow-start-if-complete="true">
            <batch:chunk reader="TrailerReader" processor="TrailerProcessor"
                writer="hibernateItemWriter" commit-interval="1" />
        </batch:tasklet>
        <batch:end on="*" />
        <batch:next on="FAILED" to="sendErrorEmail" />
    </batch:step>
    <batch:step …
Run Code Online (Sandbox Code Playgroud)

spring-batch

5
推荐指数
0
解决办法
4026
查看次数

标签 统计

spring-batch ×1