spring批处理:条件流
我需要根据工作步骤1中的某些条件来决定下一步调用哪个步骤 请注意:在步骤1中,我使用的是纯tasklet方法。例如:spring批处理:条件流,spring,spring-batch,Spring,Spring Batch,我需要根据工作步骤1中的某些条件来决定下一步调用哪个步骤 请注意:在步骤1中,我使用的是纯tasklet方法。例如: <step id="step1"> <tasklet ref="example"> </step> 请帮助,我如何在示例tasklet中添加一些代码或进行一些配置以决定下一步要调用的步骤 我已经研究了您可以在上下文文件中指定流控制,如下所示: <step id="step1"> <tasklet ref="
<step id="step1">
<tasklet ref="example">
</step>
请帮助,我如何在示例tasklet中添加一些代码或进行一些配置以决定下一步要调用的步骤
我已经研究了您可以在上下文文件中指定流控制,如下所示:
<step id="step1">
<tasklet ref="example">
<next on="COMPLETED" to="step2" />
<end on="NO-OP" />
<fail on="*" />
<!--
You generally want to Fail on * to prevent
accidentally doing the wrong thing
-->
</step>
返回新的ExitStatus(“失败”);你是说*?不,因为“*”是上下文文件中的通配符。除了
已完成
或无操作
之外,我本可以返回任何东西使作业失败
public class SampleTasklet implements Tasklet, StepExecutionListener {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
// do something
return RepeatStatus.FINISHED;
}
@Override
public void beforeStep(StepExecution stepExecution) {
// no-op
}
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
//some logic here
boolean condition1 = false;
boolean condition2 = true;
if (condition1) {
return new ExitStatus("COMPLETED");
} else if (condition2) {
return new ExitStatus("FAILED");
}
return new ExitStatus("NO-OP");
}
}