我有一个要求,我在 spring 批处理作业中有多个步骤,如果一步失败,我仍然应该继续下一步 . 但失败的步骤应该可以重新启动 .
<batch:job id="myJob" restartable="true">
<batch:step id="step1" allow-start-if-complete="false">
<batch:tasklet ref="tasklet1" start-limit="1">
</batch:tasklet>
<batch:next on="*" to="step2"/>
</batch:step>
<batch:step id="step2">
<batch:tasklet ref="tasklet2" allow-start-if-complete="true">
</batch:tasklet>
<batch:next on="*" to="step3"/>
</batch:step>
<batch:step id="step3">
<batch:tasklet ref="tasklet3" allow-start-if-complete="true">
</batch:tasklet>
<batch:next on="*" to="step4"/>
</batch:step>
<batch:step id="step4">
<batch:tasklet ref="tasklet4" allow-start-if-complete="true">
</batch:tasklet>
</batch:step>
<batch:listeners>
<batch:listener ref="myListener" />
</batch:listeners>
</batch:job>
为了测试目的,我在Tasklet3中添加了异常 .
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Tasklet4 is running");
throw new Exception("Some error");
}
我对此有很多疑问 .
-
如果在步骤3中我添加我想要执行下一步但作业无法重新启动,我无法将作业状态变为FAILED .
-
只是为了重新启动批处理作业,我改变了step3配置,然后批处理作业失败,并且没有执行第4步 . 但是allow-start-if-complete = "false"或start-limit = "1"不起作用,如果我重新启动作业,step1仍然会被执行 . 我希望step1不会在作业重启时执行 .
我的目标是步骤应该继续下一步失败,我应该能够重新启动作业(作业应该失败),并且在重新启动执行期间不应该执行上面的一些步骤(步骤1) .
请帮忙 .