Announcement Announcement Module
Collapse
No announcement yet.
Configuring Spring Batch Unexpected Error Conditions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Thanks

  • #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());
    stepExecution.setStatus(BatchStatus.COMPLETED);
    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:tasklet>
    <batch:next on="CLEANUP" to="FileCleanup"/>
    <batch:next on="*" to="CSVB"/>
    </batch:step>

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

    Comment

    Working...
    X