如果多步骤批次中的步骤失败,控制台上会显示步骤失败消息。此外,BATCH_STATUS为COMPLETED,EXIT_STATUS为FAILED.
Q.1如何将EXIT_STATUS更改为COMPLETED
问题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>如果作业someJob的步骤aStep失败(aStep抛出了一些SQLException)。然后继续执行someJob。但是在成功完成cStep之后,someJob的BATCH_STATUS是COMPLETED,但EXIT_STATUS = FAILED。其他步骤的BATCH_STATUS和EXIT_STATUS如下所示。
Step Name BATCH_STATUS EXIT_STATUS
aStep FAILED FAILED
bStep COMPLETED COMPLETED
cStep COMPLETED COMPLETED发布于 2015-01-07 00:03:17
Spring Batch中有两种状态。第一个是BatchStatus。此状态由一组预定义的值组成,框架使用这些值来指示事物的状态。另一个是ExitStatus。ExitStatus为开发人员提供了提供特定用例状态消息的能力。
在作业的执行过程中,Spring Batch不允许您覆盖BatchStatus。这是设计好的。但是,允许在许多地方设置ExitStatus (通常是像StepExecutionListener和JobExecutionListener这样的侦听器),以便可以解释来自框架的结果以满足您的用例。
如果要在ExitStatus通常显示作业或步骤已失败时指示成功,则应实现相应的监听程序并相应地设置ExitStatus。
发布于 2015-01-08 09:58:21
如果您参考页面上关于配置作业的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批处理和退出状态结束。
发布于 2021-04-09 12:14:58
您可以在xml中添加以下代码:
如果想在步骤失败时使作业失败-- 如果想在步骤失败时完成作业--
如果您想在步骤失败时在日志中打印一条消息,请包括如下异常处理:
<batch:skippable-exception-classes>
<batch:include class="java.lang.Exception" />
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener>
<bean class="java.lang.Exception" scope = "step">
</bean>
</batch:listener>
</batch:listeners> https://stackoverflow.com/questions/27793014
复制相似问题