title: Spring-Batch: how do I return a custom Job exit code from a StepListener
body: <p>The issue is this: I have a Spring Batch job with a single step. This step is called multiple times. If every time it's called everything works ok (no Exceptions) the Job status is "COMPLETED". If something bad happends at least in one of the executions of the Step (an exception is thrown) I've configured a StepListener that changes the exit code to FAILED:</p>
  
  <pre><code>public class SkipCheckingListener extends StepExecutionListenerSupport {
  
      public ExitStatus afterStep(StepExecution stepExecution) {
          String exitCode = stepExecution.getExitStatus().getExitCode();
          if (stepExecution.getProcessorSkipCount() &gt; 0) {
              return new ExitStatus(ExitStatus.FAILED);
          }
          else {
              return null;
          }
      }
  
  }
  </code></pre>
  
  <p>This works fine, when the condition is met the "if" block is exectued and the job finishes with status FAILED. Notice however that the exit code I return here is still amongst the standard ones that come with Spring Batch. I would like to return my personalized exit code such as "COMPLETED WITH SKIPS" at certain points. Now I've tried updating the above code to return just that:</p>
  
  <pre><code>public class SkipCheckingListener extends StepExecutionListenerSupport {
  
      public ExitStatus afterStep(StepExecution stepExecution) {
          String exitCode = stepExecution.getExitStatus().getExitCode();
          if (stepExecution.getProcessorSkipCount() &gt; 0) {
              return new ExitStatus("COMPLETED WITH SKIPS");
          }
          else {
              return null;
          }
      }
  
  }
  </code></pre>
  
  <p>as it is described in the docs: <a href="http://static.springsource.org/spring-batch/reference/html/configureStep.html" rel="nofollow">http://static.springsource.org/spring-batch/reference/html/configureStep.html</a> (5.3.2.1. Batch Status vs. Exit Status). I've even tried </p>
  
  <pre><code>stepExecution.getJobExecution().setExitStatus("COMPLETED WITH SKIPS");
  </code></pre>
  
  <p>And sure enough, the execution arrives in the "if" block, executes the code, and still my job finishes with exit code COMPLETED, completly ignoring the exit code I've set via the listener.</p>
  
  <p>There's no more details on this in their docs, and I haven't found anything using Google. Can someone plz tell me how do I go about changing the Job exit code in this fashion? Thanx</p>