首页 文章

spring 批步失败

提问于
浏览
1

如果多步批处理中出现步骤故障,则会在控制台上显示步骤失败消息 . BATCH_STATUS 也是 COMPLETEDEXIT_STATUSFAILED.

Q.1如何将 EXIT_STATUS 更改为 COMPLETED

Q.2无论如何都不能在控制台中显示失败消息

示例代码

<job id="someJob" xmlns="http://www.springframework.org/schema/batch"
     restartable="true" parent="baseJob">
    <step id="aStep">
        <job ref="aJob" />
        <next on="*" to="bStep"/>
    </step>
    <step id="bStep" parent="aStep" next="cStep">
        <job ref="bJob"/>
    </step>
    <step id="cStep" parent="bStep">
        <job ref="cJob"/>
    </step>
</job>

 <job id="aJob" xmlns="http://www.springframework.org/schema/batch"
         restartable="true" parent="baseJob">
    <step id="aJobStep">
        <tasklet ref="aJobTasklet" />
    </step>
</job>

<job id="bJob" xmlns="http://www.springframework.org/schema/batch"
         restartable="true" parent="baseJob">
    <step id="bJobStep">
        <tasklet ref="bJobTasklet" />
    </step>
</job>

<job id="cJob" xmlns="http://www.springframework.org/schema/batch"
         restartable="true" parent="baseJob">
    <step id="cJobStep">
        <tasklet ref="cJobTasklet" />
    </step>
</job>

如果步骤 aStep 失败了 someJobaStep 已经抛出一些 SQLException ) . 然后 someJob 继续执行 . 但在成功完成 cStep 之后, someJobBATCH_STATUSCOMPLETEDEXIT_STATUS = FAILED . 其他步骤 BATCH_STATUSEXIT_STATUS 如下 .

Step Name BATCH_STATUS  EXIT_STATUS
aStep     FAILED        FAILED
bStep     COMPLETED     COMPLETED
cStep     COMPLETED     COMPLETED

2 回答

  • 0

    Spring Batch有两种状态 . 第一个是 BatchStatus . 此状态由一组预定义值组成,框架使用这些值来指示事物的状态 . 另一个是 ExitStatus . ExitStatus 使开发人员能够提供特定于用例的状态消息 .

    在执行作业时,Spring Batch无法覆盖 BatchStatus . 这是设计的 . 但是,允许在许多位置设置 ExitStatus (通常是 StepExecutionListenerJobExecutionListener 等侦听器),以便可以解释框架的结果以满足您的用例 .

    如果要在 ExitStatus 通常表示作业或步骤失败时指示成功,则应实现相应的侦听器并相应地设置 ExitStatus .

  • 2

    如果您在页面上参考有关配置作业的Spring Batch文档(http://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html,第5.3.3节,您应该能够看到使用 <end>

    它可以通过

    <job ....>
        <step id="step1"...>
            ....
            <end on="FAILED" />
            <next on="*" to="step2" />
        </step>
        <step id="step2" ....>
            ....
        </step>
    </job>
    

    通过这样做,当step1失败时,作业将以 COMPLETED 批处理和退出状态结束 .

相关问题