【发布时间】:2016-08-25 15:05:31
【问题描述】:
我有以下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);
}
}
在第 5 次尝试后,如果 loadFile 不存在,则会引发 ItemStreamException。我怎样才能捕捉到这个异常?
我想通过向管理员发送电子邮件来处理此异常。我试过用 try catch 子句包围jobLauncher.run(job, jobParameters);,但它不起作用。
【问题讨论】:
标签: spring spring-batch spring-retry