Reputation: 669
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?
Upvotes: 1
Views: 7004
Reputation: 18413
The best choice to solve your problem is to use a JobExecutionDecider where you perform filename validation and stop job or move to next step
Upvotes: 0
Reputation: 1964
Hansjoerg's answer is a valid point. Still as for how to achieve what you're trying to do, here's an example :
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
return ExitStatus.FAILED;
}
This will return an ExitStatus FAILED
that you can use on your <next on="" />
tag to prevent from going into the reader.
Upvotes: 3
Reputation: 4454
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.
Upvotes: 4