Search code examples
spring-batchterminate

how to stop/terminate the step in execution listeners in spring batch?


I had file name validation in step execution listener . If the file name is not valid i want to terminate/stop the step from proceeding into reader . how to achieve this in sprig batch?


Solution

  • The listener is the wrong place to do data validation. use a processor and throw an appropriate exception if you have to validate single data items.

    Use a tasklet step prior to a processing step if you want to validate more "general" aspects like the filename or the presence of a file or any other condition that is not part of single item.