8

我试图归结为最简单的重试方案。执行时将忽略重试。

应用程序.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

1 回答 1

17

对方法的内部调用@Retryable(在同一个类中)不可重试;看看昨天的回答,这解释了原因。

此外,@Retryable方法必须是公开的。

于 2017-01-26T22:22:03.320 回答