2017-05-19 47 views
2

我想跟踪在阅读作业的过程中失败的记录。我为此使用了SkipListener。如何跟踪Spring批处理失败的记录?

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)方法我得到抛出对象是这样的:

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,Active,500000,34,888 我怎样才能得到这或我必须手动解析抛出对象,并得到这个?

第二个问题是:我想跟踪实际提交给作业的项目数量,跳过的项目数量,成功处理的项目数量,是否有任何由Spring Batch为此提供的支持?

回答

1

对于第一个问题,您必须手动解析异常消息,因为无法读取该项目。

关于第二个问题,SpringBatch提供有关StepExecution对象的方法:

  • 阅读:stepExecution.getReadCount()
  • 读取失败:stepExecution.getReadSkipCount()
  • 加工:stepExecution.getProcessCount()
  • 处理失败:stepExecution.getProcessSkipCount()
  • 写:stepExecution.getWriteCount()
  • 书面失败:stepExecution.getWriteSkipCount()
+0

感谢您的回答。 –

相关问题