2017-05-19 49 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

感謝您的回答。 –

相關問題