Spring-Batch: how do I return a custom Job exit STATUS from a StepListener to decide next step

一笑奈何 提交于 2019-11-29 07:40:50

They are several ways to do this.

You can use a StepExecutionListener and override the afterStep method:

@AfterStep
public ExitStatus afterStep(){
    //Test condition
    return new ExistStatus("CUSTOM EXIT STATUS");
}

Or use a JobExecutionDecider to choose the next step based on a result.

public class CustomDecider implements JobExecutionDecider  {

    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        if (/* your conditon */) {
            return new FlowExecutionStatus("OK");
        }
        return new FlowExecutionStatus("OTHER CODE HERE");
    }

}

Xml config:

    <decision id="decider" decider="decider">
        <next on="OK" to="step1" />
        <next on="OHTER CODE HERE" to="step2" />
    </decision>

<bean id="decider" class="com.xxx.CustomDecider"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!