作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是这样的:我只有一个步骤就能完成一个Spring Batch作业。此步骤称为多次。如果每次调用它,一切正常(无异常),则作业状态为“已完成”。如果至少在执行步骤之一中发生了问题(抛出异常),我已经配置了一个StepListener,将退出代码更改为FAILED:
public class SkipCheckingListener extends StepExecutionListenerSupport {
public ExitStatus afterStep(StepExecution stepExecution) {
String exitCode = stepExecution.getExitStatus().getExitCode();
if (stepExecution.getProcessorSkipCount() > 0) {
return new ExitStatus(ExitStatus.FAILED);
}
else {
return null;
}
}
}
public class SkipCheckingListener extends StepExecutionListenerSupport {
public ExitStatus afterStep(StepExecution stepExecution) {
String exitCode = stepExecution.getExitStatus().getExitCode();
if (stepExecution.getProcessorSkipCount() > 0) {
return new ExitStatus("COMPLETED WITH SKIPS");
}
else {
return null;
}
}
}
stepExecution.getJobExecution().setExitStatus("COMPLETED WITH SKIPS");
最佳答案
看起来您只是无法更改BatchStatus,但是可以使用exitstatus尝试
带有JobListener的代码对我有用
// JobListener with interface or annotation
public void afterJob(JobExecution jobExecution) {
jobExecution.setExitStatus(new ExitStatus("foo", "fooBar"));
}
关于java - Spring-Batch:如何从StepListener返回自定义Job退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879550/
问题是这样的:我有一个包含多个步骤的 Spring Batch 作业。根据第一步,我必须决定下一步。我可以根据作业参数在 STEP1- passTasklet 中设置状态,以便我可以将退出状态设置为自
我编写了一个JobStepListener,需要在每个步骤之前和之后执行。然而,每个作业都包含许多步骤(超过 1000 个步骤),并且在每个步骤中插入监听器会很乏味,特别是因为我有多个作业需要此功能。
我是一名优秀的程序员,十分优秀!