我正在尝试获取最后完成的作业的执行上下文。下面是代码:
@Component
public class MyJobDataReader implements ItemReader<MyDbEntity>, StepExecutionListener {
@Autowired
@Qualifier("jobService")
JobService jobService;
@Override
public void beforeStep(StepExecution stepExecution) {
Collection<JobExecution> jobExecutions = null;
try {
jobExecutions = jobService.listJobExecutionsForJob("myjob", 0, jobService.countJobExecutionsForJob("myjob"));
} catch (NoSuchJobException e) {
//log
}
JobExecution lastCompletedJobExecution =
jobExecutions
.stream()
.filter(param -> param.getExitStatus().getExitCode().equals(ExitStatus.COMPLETED.getExitCode()))
.findFirst()
.orElse(null);
Long myExecutionContextParam =
lastCompletedJobExecution
.getExecutionContext()
.getLong(contextParam);
}
}
但是即使我在myExecutionContextParam
表中看到了所获取的作业执行的值,我也将BATCH_JOB_EXECUTION_CONTEXT
也设置为null。
答案 0 :(得分:0)
问题是jobService.listJobExecutionsForJob
返回的JobExecution字段很少,然后我不得不打电话给jobService.getJobExecution(jobExecutionId)
以获取完全丰富的JobExecution