How to get job id using spring expression language?

吃可爱长大的小学妹 提交于 2019-12-01 03:13:43

问题


I want to get job id using spring expression language. I tried #{jobExecutionContext[jobId]} but it does not work.


回答1:


Using SpEL alone, there is no way to access the job id. You could use a JobExecutionListener to add it to the executionContext and then it would be available via what you are trying.




回答2:


A worked example would look like this. Your JobExecutionListener class has access to the JobExecution and it copies the jobId to the executionContext.

public class JobIdToContextExecutionListener implements JobExecutionListener {

    public void beforeJob(JobExecution jobExecution) {
        long jobId = jobExecution.getJobId();
        jobExecution.getExecutionContext().put("jobId",jobId);
    }

    ..
}

In your spring context, you can then reference the jobId via SpEL like

#{stepExecution.jobExecution.jobId}

or

#{jobExecutionContext.jobId}

See Luca's answer on referencing late-binding parameters here.




回答3:


#{stepExecution.jobExecution.id} or #{stepExecution.jobExecutionId} should work though.

The StepContext does provide access to the StepExecution for late binding via SpEL expressions.




回答4:


Use scope="step" and then an expression in your query (or its parameters): #{stepExecution.jobExecution.id} (the root of the expression is a StepContext).



来源:https://stackoverflow.com/questions/17149302/how-to-get-job-id-using-spring-expression-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!