title: Spring Batch not executing StepExecutionListener beforeStep or afterStep methods
body: <p><strong>Update:</strong> I was re-running my code and actually noticed none of my Listeners are actually working...</p>
  <p>I have a Spring Batch application and I am overriding the StepExecutionListener and providing my own implementation. I am registering it with the TaskletStep, however, I never see the log messages that the beforeStep/afterStep methods should be outputting:</p>
  <p><strong>MyStepExecutionListener.java</strong></p>
  <pre><code>public class MyStepExecutionListener implements StepExecutionListener {
  
   @Override
      public void beforeStep(StepExecution stepExecution) {
          // begin my own custom implementation
          LOGGER.info(&quot;Before the step!&quot;);
      }
  
      @Override
      public ExitStatus afterStep(StepExecution stepExecution) {
           // begin my own custom implementation
           LOGGER.info(&quot;After the step!&quot;);
          return stepExecution.getStatus();
  
      }
  }
  </code></pre>
  <p>I have defined my Tasklet Step in my <strong>BatchConfig.java</strong> class as:</p>
  <pre><code>public BatchConfig {
  
  @Bean
      public static org.springframework.batch.core.scope.JobScope jobScope() {
          org.springframework.batch.core.scope.JobScope jobScope = new org.springframework.batch.core.scope.JobScope();
          jobScope.setProxyTargetClass(true);
          jobScope.setAutoProxy(true);
          return jobScope;
      }
  
      @Bean
      public static org.springframework.batch.core.scope.StepScope stepScope() {
          org.springframework.batch.core.scope.StepScope stepScope = new org.springframework.batch.core.scope.StepScope();
          stepScope.setProxyTargetClass(true);
          stepScope.setAutoProxy(true);
          return stepScope;
      }
  
      @Bean
  //    @StepScope
      public StepExecutionListener stepExecutionListener() {
          return new MyStepExecutionListener();
      }
  
   @Bean
      @Qualifier(&quot;s3FlatfFileReaderForMktgOffrs&quot;)
      @StepScope
      public S3FlatFileItemReader&lt;FieldSet&gt; s3FlatfFileReaderForMktgOffrs() {
          return new S3FlatFileItemReader&lt;&gt;(lineMapper());
      }
  
   @Bean
      @Qualifier(&quot;s3FlatfFileReaderCustom&quot;)
      @StepScope
      public S3FlatFileItemReader&lt;FieldSet&gt; s3FlatfFileReaderCustom() {
          // Custom class that Extends FlatFileItemReader
          return new S3FlatFileItemReader&lt;&gt;(lineMapper());
      }
  
    @Bean
      @Qualifier(&quot;myCustomFileItemReader&quot;)
      @StepScope
      public ItemStreamReader&lt;List&lt;FieldSet&gt;&gt; myCustomFileItemReader(
              @Value(&quot;#{jobParameters}&quot;) Map jobParameters) {
  
          String fileName = (String) jobParameters.get(&quot;fileName&quot;);
          String region = (String) jobParameters.get(&quot;region&quot;);
          String bucketName = awsS3EastBucket;
          if (StringUtils.equals(region, Regions.US_WEST_2.getName())) {
              bucketName = awsS3WestBucket;
          }
  
          // Custom class that Extends FlatFileItemReader
          S3FlatFileItemReader&lt;FieldSet&gt; s3FileItemReader = s3FlatfFileReaderCustom();
  
       
           s3FileItemReader.setResource(S3_PROTOCOL_PREFIX + bucketName + SLASH + fileName);
          }
  
          s3FileItemReader.setStrict(false);
          s3FileItemReader.setLinesToSkip(1);
          s3FileItemReader.setSaveState(false);
  
          AggregateItemReader aggregateItemReader = new AggregateItemReader(s3FileItemReader) {
              @Override
              protected String getItemKey(FieldSet item) {
                  return item.readString(FIRST_NAME) + &quot;-&quot; +
                          item.readString(LAST_NAME);
              }
          };
          SynchronizedItemStreamReader&lt;List&lt;FieldSet&gt;&gt; fieldSetSynchronizedItemStreamReader = new SynchronizedItemStreamReader&lt;&gt;();
          fieldSetSynchronizedItemStreamReader.setDelegate(aggregateItemReader);
          return fieldSetSynchronizedItemStreamReader;
      }
  
  
  
  @Bean(name = &quot;myCustomStep&quot;)
      @Scope(&quot;prototype&quot;)
      @SuppressWarnings(&quot;unchecked&quot;)
      public Step myCustomStep(PlatformTransactionManager transactionManager) {
          TaskletStep step = stepBuilderFactory.get(&quot;myCustomStep&quot;)
                  .&lt;List&lt;FieldSet&gt;, List&lt;MyPayLoadRecord&gt;&gt;chunk(250)
                  .reader(myCustomFileItemReader(OVERRIDDEN_BY_EXPRESSION))
                  .processor(myCustomProcessor())
                  .writer(myCustomWriter())
                  .faultTolerant()
                  .skipPolicy(new AlwaysSkipItemSkipPolicy())
                  .skip(DataValidationException.class)
                  .listener(stepExecutionListener())
                  .listener(new CustomReaderListener())
                  .listener(new CustomProcessListener())
                  .listener(new CustomWriteListener())
                  .listener(new CustomSkipListener())
                  .taskExecutor(batchTaskExecutor())
                  .throttleLimit(maxThreads)
                  .build();
          step.setTransactionManager(transactionManager);
          //step.registerStepExecutionListener(stepExecutionListener());
          step.registerChunkListener(new CustomChunkListener());
          return step;
      }
  }
  </code></pre>
  <p>I have commented out <code>step.registerStepExecutionListener(stepExecutionListener());</code> and tried setting the listener as seen above, but neither implementation worked. I was under the impression I should just implement the StepExecutionListener then register it with the TaskletStep - am I missing something here?</p>