作业执行侦听器无法将值存储在作业执行上下文表中

时间:2018-07-25 07:58:55

标签: spring-boot spring-batch batch-processing

我已经实现了将执行成功和失败的处理数存储到作业执行上下文中的JobExecutionListener的afterJob()方法中的功能:

    public void afterJob(JobExecution jobExecution) {
    final long jobExecutionId = jobExecution.getId();
    final BatchStatus jobStatus = jobExecution.getStatus();
    final ExecutionContext jobExecutionContext = jobExecution.getExecutionContext();

    String exitCodeAndMessage = null;
    Map<String, Integer> recordsProcessed = null;

    switch (jobStatus) {
        case COMPLETED:
            //exitCodeAndMessage = getExitCodeAndMessageFromEveryStep(jobExecution);
            recordsProcessed = getExitCodeAndMessageFromEveryStep(jobExecution);
            if (exitCodeAndMessage == null) {
                exitCodeAndMessage = "COMPLETED";
            }
            jobExecutionContext.putString("AfterJob", "Success");
            jobExecutionContext.put("recordsProcessed", recordsProcessed);
            break;

运行作业后,表内没有存储任何值。为什么?

1 个答案:

答案 0 :(得分:0)

作业完成后不会保存作业执行上下文,而是在每个步骤执行之间保存。因此,您可以使用 User1 | User2 ----------------------------------------------------- Project A | Project X Project B | Project Y Project C | 并将这些指标添加到gcloud config list方法中。此处的更多详细信息:https://docs.spring.io/spring-batch/4.0.x/reference/html/domain.html#executioncontext