Spring batch 弹簧批级失效
如果多步骤批处理中出现步骤失败,控制台上将显示步骤失败消息。 此外,Spring batch 弹簧批级失效,spring-batch,Spring Batch,如果多步骤批处理中出现步骤失败,控制台上将显示步骤失败消息。 此外,批处理状态为已完成,退出状态为失败。 问题1如何将退出状态更改为完成状态 Q.2控制台中是否可能不显示故障消息 示例代码 <job id="someJob" xmlns="http://www.springframework.org/schema/batch" restartable="true" parent="baseJob"> <step id="aStep">
批处理状态
为已完成
,退出状态
为失败。
问题1如何将退出状态更改为完成状态
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>
Spring批处理中有两种状态。第一个是
BatchStatus
。此状态由一组预定义的值组成,框架使用这些值来指示事物的状态。另一个是退出状态。ExitStatus
为开发人员提供了提供特定于用例的状态消息的能力
在作业的执行过程中,Spring Batch不允许您覆盖BatchStatus
。这是故意的。但是,ExitStatus
允许在多个位置设置(通常是像StepExecutionListener
和JobExecutionListener
这样的侦听器),以便解释框架的结果以满足您的用例
如果要在
ExitStatus
通常表示作业或步骤失败时指示成功,则应实现适当的侦听器并相应地设置ExitStatus
。如果您参考页面上有关配置作业的Spring Batch文档(,第5.3.3节),您应该能够看到
这可以通过
<job ....>
<step id="step1"...>
....
<end on="FAILED" />
<next on="*" to="step2" />
</step>
<step id="step2" ....>
....
</step>
</job>
....
....
这样,当步骤1失败时,作业将以批处理和退出状态结束。您可以在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>
你的意思是想忽略步骤中发生的错误吗?我想如果步骤1失败,你可以使用Flow来忽略步骤2,因为Element将在你的cStep
帮助中放置
?返回ExitStatus.COMPLETED from the after step of StepListener of“aStep”返回ExitStatus仍不工作批次状态为已完成,退出状态为FAILED@Overridepublic ExitStatus afterStep(StepExecution StepExecution){//在多步骤批处理的每个步骤中调用步骤侦听器//如果条件仅在所需步骤清除异常列表If(StringUtils.equals(StepExecution.getStepName(),“aStep”)){stepExecution.getFailureExceptions().clear();stepExecution.getJobExecution().getAllFailureExceptions().clear();stepExecution.setExitStatus(ExitStatus.COMPLETED);return ExitStatus.COMPLETED;}return null;}现在批处理状态=已完成,退出状态=已完成,即使“aStep”失败。
<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>