在决策器中访问Spring Batch作业参数

时间:2019-05-16 16:36:59

标签: java spring spring-batch

我有一个春季批处理作业,我在其中放置了一个文件名作为作业参数,我需要在决策程序中使用此参数。

我的决定者:

public class MyDecider implements JobExecutionDecider
{     
    public FlowExecutionStatus decide(JobExecution jobExecution,
              org.springframework.batch.core.StepExecution stepExecution)
    {
        String fileName=jobExecution.getExecutionContext().getString("file");
        System.out.println(" filae name from step execution : "+fileName);
        FileRead fileRead=new FileRead();
        if (fileName.equals("aaaa"))
    {
            return FlowExecutionStatus.COMPLETED;
        }
    else 
        {
            return FlowExecutionStatus.FAILED;
        }      
    }
}

1 个答案:

答案 0 :(得分:1)

JobExecutionDecider#decide方法使用类型为JobExecution的参数,该参数允许您使用JobExecution.getJobParameters获取作业参数。这是一个简单的示例:

class MyDecider implements JobExecutionDecider {

    @Override
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        JobParameters jobParameters = jobExecution.getJobParameters();
        // get the job parameter from jobParameters
        return null; // return the FlowExecutionStatus as needed
    }
}