2017-01-26 94 views
0

我試圖簡化最簡單的重試方案。執行後,重試將被忽略。@Retryable未被觸發

Application.java:

@SpringBootApplication 
@EnableRetry 
public class Application extends SpringBootServletInitializer { 
//... 

這是一個服務類中:

public Boolean processItem() { 
    Long id = 999L; 
    try { 
     retrieveItemWithRetry(id); 
     return true; 
    } catch (NoResultException e) { 
     return false; 
    } 
} 

@Retryable(include=NoResultException.class, backoff = @Backoff(delay = 500, maxDelay = 3000), maxAttempts = 5) 
private void retrieveItemWithRetry(Long id) { 
    retrieveItem(id); 
} 

private OrderRequest retrieveItem(Long id) { 
    throw new NoResultException(); 
}  

回答

4

內部調用@Retryable方法(在相同類中)不重試;從昨天看my answer here,這解釋了原因。

此外,@Retryable方法必須公開。

+0

感謝@Gary,爲了記錄,我還必須確保'@ Retryable'類是注入到調用類的'@ Component'類。 –