首页 > 解决方案 > Xml Spring批处理作业像if else一样执行

问题描述

我做了春季批量工作,但我卡在了某个地方。我正在尝试在春季批处理 XML 作业中从用户那里获取参数,基于该参数我将运行不同的步骤。

例如。Argument= new 或 replace 基于 "Argument" ,将执行不同的步骤 If argument=new then step 1 Else If argument=replace then step 2 Else some error

非常感谢您的任何领导或帮助。

标签: xmlspringspring-batchjava-batch

解决方案


您可以根据系统属性创建决策程序来决定使用哪个步骤,例如:

class MyDecider implements JobExecutionDecider {

    @Override
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        String operation = System.getProperty("operation");
        if (operation.equalsIgnoreCase("create"))
            return new FlowExecutionStatus("create");
        else {
            return new FlowExecutionStatus("update");
        }
    }
}

然后在你的工作定义中使用这个决定器:

<beans:bean id="decider" class="MyDecider"/>

<job id="job">
    <step id="step1" next="decision" />

    <decision id="decision" decider="decider">
        <next on="create" to="createStep" />
        <next on="update" to="updateStep" />
    </decision>

    <step id="createStep"/>
    <step id="updateStep"/>
</job>

推荐阅读