我正在使用Spring Batch
3.0.7.RELEASE 版本
关于跳过 我有以下内容:
<batch:chunk reader="personErrorSkipFileItemReader"
processor="personErrorSkipItemProcessor"
writer="personErrorSkipFileItemWriter"
commit-interval="100"
skip-limit="11">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
<batch:include class="com.manuel.jordan.batch.exception.PersonBatchException"/>
</batch:skippable-exception-classes>
</batch:chunk>
它按预期工作。
出于日志记录和测试目的,我需要检索以下数据:
- 跳过的元素(例如 8 个,共 11 个(,显示数量,例如:
- 通过
FlatFileParseException
5 - 通过
PersonBatchException
3
如果可以显示每个跳过的项目在哪个步骤和区域(读取器、处理器、写入器(中被抛出,那就更好了。
通过JobExecution工作,我有以下内容
List<Throwable> exceptions = jobExecution.getAllFailureExceptions();
logger.info("exceptions size: {}", exceptions.size());
for(Throwable throwable : exceptions){
logger.error("Throwable Class: {}", throwable.getClass().getSimpleName());
logger.error("{}", throwable.getMessage());
}
List<Throwable> exceptions_ = jobExecution.getFailureExceptions();
logger.info("exceptions_ size: {}", exceptions_.size());
for(Throwable throwable : exceptions_){
logger.error("Throwable Class: {}", throwable.getClass().getSimpleName());
logger.error("{}", throwable.getMessage());
}
但是两个集合的大小都大于 1,并且仅在作业完成时显示异常FAILED
。
由于 8 <11,因此Job
完成COMPLETED
和列表大小的方式返回 0。
实现SkipListener,它有三个回调方法
1 :onSkipInProcess2 :onSkipInWrite3:在跳过阅读
http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/SkipListener.html