问题
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