0
votes

I have just started working on Spring Batch (version 3.0.6). I have a job and inside step I'm having Reader->Processor->Writer.

How we can catch or identify the exception is thrown if file is not found while reading. In this case I want to trigger email.

1

1 Answers

0
votes

You can use the StepExecutionListener to process the exception that is thrown by the ItemStream#open (as the opening of a file in the FlatFileItemReader is), sending your email from there. To get the exception that caused the failure, you can look at StepExecution#getFailureExceptions which will contain the exception that caused the step to fail.

You can read more about the StepExecutionListener in the javadoc here: https://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/StepExecutionListener.html