LoggerContextStepListener implements StepExecutionListener, InitializingBean { @Override public void beforeStep(StepExecution stepExecution) { MDC.put(STEP_NAME, stepExecution.getStepName().replace(':', '-')); MDC.put(STEP_EXECUTION_ID, stepExecution.getId().toString()); addFromJobParametersExtractor(stepExecution); }  @Override void afterPropertiesSet(); @Override void beforeStep(StepExecution stepExecution); @Override ExitStatus afterStep(StepExecution stepExecution); void setJobParametersExtractor(JobParametersExtractor jobParametersExtractor); void setDateFormat(String dateFormat); static final String STEP_NAME; static final String STEP_EXECUTION_ID; }
@Test public void testBeforeJob() throws Exception { listener.beforeStep(stepExecution); Assert.assertEquals(TRAIN_ID.toString(), MDC.get(TRAIN_ID_KEY)); Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd").format(DATE), MDC.get(DATE_KEY)); Assert.assertEquals(STEP_NAME, MDC.get(LoggerContextStepListener.STEP_NAME)); Assert.assertEquals(STEP_EXECUTION_ID.toString(), MDC.get(LoggerContextStepListener.STEP_EXECUTION_ID)); }