我遇到的情况是步骤可以抛出自定义异常并且作业的执行因异常而停止。我面临的问题是,在“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 ×1