title: Stop processing on Spring Batch
body: <p>I'm quite newbie to Spring Batch and I'm having some problems.
  I have a spring batch step, which has a reader, a chain of item processors with 2 processors and a writer. I'd like to stop the second processor from running when the first finishes with error.
  I've tried using a StepExecutionListener returning ExistStatus.FAILED but no success. I've also tried adding a ItemProcessListener to do some action on the onProcessError method, but nothing.
  Any ideas on how can I do that?</p>
  
  <p>Here is the code I'm using to configure the step.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.batch.core.Step;
  import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
  import org.springframework.batch.item.ItemProcessor;
  import org.springframework.batch.item.ItemReader;
  import org.springframework.batch.item.ItemWriter;
  import org.springframework.batch.item.support.CompositeItemProcessor;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class StepConfig {
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Autowired
      private ItemReader&lt;String&gt; flatFileItemReader;
  
      @Autowired
      private ItemWriter&lt;ResponseTO&gt; itemWriter;
  
      @Bean
      public Step buildStep() {
                return stepBuilderFactory.get("step")
                  .&lt;String, ResponseTO&gt; chunk(1)
                  .reader(flatFileItemReader)
                  .processor(chainOfItemsProcessors())
                  .writer(itemWriter)
                  .faultTolerant()
                  .build();
      }
  
      private CompositeItemProcessor&lt;String, ResponseTO&gt; chainOfItemsProcessors() {
          CompositeItemProcessor&lt;String,ResponseTO&gt; compositeProcessor = new CompositeItemProcessor&lt;&gt;();
          List&lt;ItemProcessor&lt;?, ?&gt;&gt; itemProcessors = new ArrayList&lt;&gt;();
          itemProcessors.add(processor1);
          itemProcessors.add(processor2);
          compositeProcessor.setDelegates(itemProcessors);
          return compositeProcessor;
      }
  }
  </code></pre>