Announcement Announcement Module
No announcement yet.
Configuring Spring Batch Unexpected Error Conditions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring Spring Batch Unexpected Error Conditions

    I was wondering if there was a way to have Spring Batch do the following:

    Say I have 3 steps A, B and C and I have a file clean up task on Step D.

    I process step A, and start on B and I get a totally unexpected exception -- say a null pointer exception or class cast exception -- something totally unexpected.

    I want to completely stop task B (or A or C) and go to my file clean up task on Step D and then complete my job.


  • #2
    For what it is worth, I seemed to have figured it out. For future reference (I didn't find many crystal clear examples out on the web) here is what I did:

    On each step's afterStep method, I added the following:

    if ( stepExecution.getStatus().equals(BatchStatus.FAILE D)) {
    logTheError(stepExecution.getExitStatus().getExitD escription());
    exitStatus = new ExitStatus("CLEANUP", "Cleanup");

    Then in my spring xml configuration I did the following for each step:

    <batch:step id="CSVA">
    <batch:tasklet transaction-manager="transactionManager">
    <batch:chunk reader="CSVAReader" processor="CSVAProcessor" writer="CSVAWriter" commit-interval="1"/>
    <batch:next on="CLEANUP" to="FileCleanup"/>
    <batch:next on="*" to="CSVB"/>

    If anyone sees any problems with that, please let me know, but it appears to work.