Spring batch 如何跟踪Spring批处理中的失败记录?
我想记录在作业的读取步骤中失败的记录。我用了斯基普利斯腾纳Spring batch 如何跟踪Spring批处理中的失败记录?,spring-batch,Spring Batch,我想记录在作业的读取步骤中失败的记录。我用了斯基普利斯腾纳 public class SkipListener implements org.springframework.batch.core.SkipListener { public void onSkipInProcess(Object arg0, Throwable arg1) { } public void onSkipInRead(Throwable arg0) { System.ou
public class SkipListener implements org.springframework.batch.core.SkipListener {
public void onSkipInProcess(Object arg0, Throwable arg1) {
}
public void onSkipInRead(Throwable arg0) {
System.out.println(arg0);
}
public void onSkipInWrite(Object arg0, Throwable arg1) {
}
}
我想将读卡器跳过的行存储在另一个csv文件中。
从上面的onSkipInRead(Throwable arg0)
方法中,我得到了如下的Throwable对象:
org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 5 in resource=[class path resource [files/input2.csv]], input=[1005,anee,Active,500000,34,888]
我只想记录为:1005,anee,活动,500000,34888
我如何才能得到这个,或者我必须手动解析throwable对象并得到这个
第二个问题是:我想跟踪实际提交到作业的项目数、跳过的项目数、成功处理的项目数,Spring Batch是否对此提供了任何支持?对于第一个问题,您必须手动解析异常消息,因为无法读取该项目 对于第二个问题,SpringBatch提供了有关对象的方法:
- 读取:
stepExecution.getReadCount()
- 读取失败:
stepExecution.getReadSkipCount()
- 已处理:
stepExecution.getProcessCount()
- 处理失败:
stepExecution.getProcessSkipCount()
- 写入:
stepExecution.getWriteCount()
- 写入失败:
stepExecution.getWriteSkipCount()