title: How to manually fail a Spring Batch job?
body: <p>This is something I need to do for testing purposes. I need a way to fail a Spring Batch job whenever I want based on certain preset conditions (such as number of items processed). However, I haven't been able to find anything like this so far. </p>
  
  <p>I have found that Spring Batch has something like this - </p>
  
  <pre><code>&lt;step id="step1" parent="s1" next="step2"&gt;
  
  &lt;step id="step2" parent="s2"&gt;
      &lt;fail on="FAILED" exit-code="EARLY TERMINATION"/&gt;
      &lt;next on="*" to="step3"/&gt;
  &lt;/step&gt;
  
  &lt;step id="step3" parent="s3"&gt;
  </code></pre>
  
  <p>But what I am looking for is something like this- </p>
  
  <pre><code>public void myJobFailingMethod()
   {
      if(conditionsMatch())
       {
          // fail the job 
       }  
   }
  </code></pre>
  
  <p>How to do this?</p>
  
  <p>Update: The Job can be failed outside a step as well. </p>