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

孤人 提交于 2019-12-13 07:41:16

问题


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?


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/34005152/how-to-stop-terminate-the-step-in-execution-listeners-in-spring-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!