TheLifeOfParallax
TheLifeOfParallax

Reputation: 55

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

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.

Upvotes: 1

Views: 2204

Answers (1)

Binu
Binu

Reputation: 784

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.

Upvotes: 3

Related Questions