Source:
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AbstractJob) { JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext.getBean("jobExecutionEventsListener"); AbstractJob job = (AbstractJob) bean; job.registerJobExecutionListener( jobExecutionEventsListener); } if (bean instanceof AbstractStep) { StepExecutionListener stepExecutionListener = (StepExecutionListener) this.applicationContext.getBean("stepExecutionEventsListener"); AbstractStep step = (AbstractStep) bean; step.registerStepExecutionListener(stepExecutionListener); if (bean instanceof TaskletStep) { TaskletStep taskletStep = (TaskletStep) bean; taskletStep.registerChunkListener((ChunkListener) this.applicationContext.getBean("chunkEventsListener")); Tasklet tasklet = taskletStep.getTasklet(); if (tasklet instanceof ChunkOrientedTasklet) { Field chunkProviderField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProvider"); ReflectionUtils.makeAccessible(chunkProviderField); SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils.getField(chunkProviderField, tasklet); Field chunkProcessorField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProcessor"); ReflectionUtils.makeAccessible(chunkProcessorField); SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils.getField(chunkProcessorField, tasklet); chunkProvider.registerListener((ItemReadListener) this.applicationContext.getBean("itemReadEventsListener")); chunkProvider.registerListener((SkipListener) this.applicationContext.getBean("skipEventsListener")); chunkProcessor.registerListener((ItemProcessListener) this.applicationContext.getBean("itemProcessEventsListener")); chunkProcessor.registerListener((ItemWriteListener) this.applicationContext.getBean("itemWriteEventsListener")); } } } return bean; }

Target:
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AbstractJob) { JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext.getBean( BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER); AbstractJob job = (AbstractJob) bean; job.registerJobExecutionListener( jobExecutionEventsListener); } if (bean instanceof AbstractStep) { StepExecutionListener stepExecutionListener = (StepExecutionListener) this.applicationContext.getBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER); AbstractStep step = (AbstractStep) bean; step.registerStepExecutionListener(stepExecutionListener); if (bean instanceof TaskletStep) { TaskletStep taskletStep = (TaskletStep) bean; taskletStep.registerChunkListener((ChunkListener) this.applicationContext.getBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER)); Tasklet tasklet = taskletStep.getTasklet(); if (tasklet instanceof ChunkOrientedTasklet) { Field chunkProviderField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProvider"); ReflectionUtils.makeAccessible(chunkProviderField); SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils.getField(chunkProviderField, tasklet); Field chunkProcessorField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProcessor"); ReflectionUtils.makeAccessible(chunkProcessorField); SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils.getField(chunkProcessorField, tasklet); chunkProvider.registerListener((ItemReadListener) this.applicationContext.getBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)); chunkProvider.registerListener((SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)); chunkProcessor.registerListener((ItemProcessListener) this.applicationContext.getBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)); chunkProcessor.registerListener((ItemWriteListener) this.applicationContext.getBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)); chunkProcessor.registerListener((SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)); } } } return bean; }