2016-08-04 64 views
0

如何讓Spring Batch在一段時間後重試失敗的步驟?如何讓Spring Batch在一段時間後重試失敗的步驟?

如果該步驟失敗超過x次,我想不再重試該步驟並使整個作業失敗。

我正在使用Java Config,並且寧願不要使用XML來配置重試。

+0

http://docs.spring.io/ spring-batch/trunk/reference/html/retry.html –

回答

2

如果您在版本2.2.0之前使用Spring Batch,則使用Retryfunctionality included in the Spring Batch library

正如上面引述的Spring Batch的文檔頁面的開頭重試注意:

重試功能被拉出春批爲2.2.0。現在是

重試功能從2.2.0版的Spring Batch中退出。它現在是新圖書館的一部分,Spring Retry。

否則直接使用Spring Retry直接(分拆的Spring Batch的項目),它是將一些不錯的聲明方式來註釋功能,你需要:

@Service 
class MyService { 
    //... 
    @Retryable(maxAttempts=5, [email protected](delay=100, maxDelay=500)) 
    public myFunctionalityService() { 
     // ... 
    } 
    // ... 
} 
+0

謝謝。這非常有幫助。我如何將這個應用到Spring Batch步驟? – James

+0

您嘗試將其首先添加到ItemReader的讀取功能 –

+0

我試過了,但這不起作用。 – James