How to get Step Name and Step Execution ID in ItemReadListener?

和自甴很熟 提交于 2021-02-10 14:14:24

问题


My Spring Batch job uses a FlatFileItemReader to read .csv files. To implement error handling, I created a custom ItemReadListener and provided an overridden onReadError implementation.

Here, I'd like access to the StepName and StepExecutionId from which the error was thrown (i.e. at the reader level). Can I access the StepExecution in the my custom listener? When I try to inject it into any method or constructor, I get a "No beans of type StepExecution found" error.

Thanks.


回答1:


Try with the following in your ItemReadListener.

@Value("#{stepExecution}")
private StepExecution stepExecution;

This should work if the scope is step. Also your ItemReadListener should be a spring bean.



来源:https://stackoverflow.com/questions/59709205/how-to-get-step-name-and-step-execution-id-in-itemreadlistener

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