title: how register via java config a listener without StepExecutionListener implementation neither StepListenerExecutionSupport extending
body: <p>I am studding Spring Batch in Action book and I found StopListener example in page 114/115. How can I register a listener class which doesn't implement StepExecutionListener neither extend StepListenerExecutionSupport? I am not using Spring Xml configuration so I have to convert the example provided in xml to java configuration.</p>
  
  <p>According to the book</p>
  
  <pre><code>public class StopListener {
    private StepExecution stepExecution;
    @BeforeStep
    public void beforeStep(
        StepExecution stepExecution) {
      this.stepExecution = stepExecution;
    }
   @AfterRead
    public void afterRead() {
      if(stopConditionsMet()) {
        stepExecution.setTerminateOnly();
      }
    }...
  
  &lt;bean id="stopListener" class="com.manning.sbia.ch04.stop.StopListener" /&gt; 
  &lt;batch:job id="importProductsJob"&gt;
    &lt;batch:step id="importProductsStep"&gt;
      &lt;batch:tasklet&gt;
        &lt;batch:chunk reader="reader" writer="writer" commit-interval="100"/&gt;
        &lt;batch:listeners&gt;
          &lt;batch:listener ref="stopListener" /&gt;
        &lt;/batch:listeners&gt;
      &lt;/batch:tasklet&gt;
    &lt;/batch:step&gt;
  &lt;/batch:job&gt;
  </code></pre>
  
  <p>As I tried:</p>
  
  <pre><code>...
         @Bean
         public StepExecutionListener stepListener(){
                return new StopListener(); //obviously, it raises casting issues
         }
  
         @Bean
         public Step stepA(ItemReader&lt;String&gt; readerA, ItemWriter&lt;String&gt; writerA,
                       StepExecutionListener stepListener) {  
                return stepBuilderFactory.get("stepA").&lt;String, String&gt; chunk(1)
                             .reader(readerA).writer(writerA).allowStartIfComplete(false)
                             .startLimit(1).listener(stepListener).build();
         }
  
  @Component
  public class StopListener {
         private StepExecution stepExecution;
         private static final Logger log = LoggerFactory.getLogger(StopListener.class);
  
         @BeforeStep
         public void beforeStep(StepExecution stepExecution) {
                log.info("StopListener.beforeStep()");
                this.stepExecution = stepExecution;
         }
  
         @AfterRead
         public void afterRead() {
                if (true) {
                       stepExecution.setTerminateOnly();
                }
         }
  }
  </code></pre>