I have the following ItemReader
:
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.LineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
@Service
public class MyReader extends FlatFileItemReader<Holding> {
@Autowired
public MyReader(LineMapper<Holding> lineMapper, File loadFile) {
setResource(new FileSystemResource(loadFile));
final int NUMBER_OF_HEADER_LINES = 1;
setLinesToSkip(NUMBER_OF_HEADER_LINES);
setLineMapper(lineMapper);
}
@Override
@Retryable(value=ItemStreamException.class, maxAttempts=5, backoff=@Backoff(delay=1800000))
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
}
}
After the 5th attempt, ItemStreamException is thrown if the loadFile
does not exist. How can I catch this exception?
I want to handle this exception by sending an email to an admin. I've tried surrounding jobLauncher.run(job, jobParameters);
with the try catch clause but it doesn't work.