title: Get last completed jobs execution context spring batch
body: <p>I am trying to fetch execution context of last completed job. Below is the code:</p>
  
  <pre><code>@Component
  public class MyJobDataReader implements ItemReader&lt;MyDbEntity&gt;, StepExecutionListener {
  
      @Autowired
      @Qualifier("jobService")
      JobService jobService;
  
      @Override
      public void beforeStep(StepExecution stepExecution) {
          Collection&lt;JobExecution&gt; jobExecutions = null;
          try {
              jobExecutions = jobService.listJobExecutionsForJob("myjob", 0, jobService.countJobExecutionsForJob("myjob"));
          } catch (NoSuchJobException e) {
              //log
          }
  
          JobExecution lastCompletedJobExecution =
                  jobExecutions
                  .stream()
                  .filter(param -&gt; param.getExitStatus().getExitCode().equals(ExitStatus.COMPLETED.getExitCode()))
                  .findFirst()
                  .orElse(null);
  
          Long myExecutionContextParam = 
                  lastCompletedJobExecution
                  .getExecutionContext()
                  .getLong(contextParam);
      }
  }
  </code></pre>
  
  <p>But I am getting the <code>myExecutionContextParam</code> also null , even though I see the value in <code>BATCH_JOB_EXECUTION_CONTEXT</code> table for the fetched job execution.</p>