This question already has an answer here:
Using @Retryable in methods define in spring bean's base class are not retried

(1 个回答)


9 个月前关闭。




我试图将最简单的重试场景归结为可能。执行时忽略重试。

应用程序.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();
}

最佳答案

@Retryable 方法的内部调用(在同一个类中)是不可重试的;请参阅昨天的 my answer here,这解释了原因。

此外,@Retryable 方法必须是公共(public)的。

关于spring - @Retryable 没有被触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41883812/

10-11 00:59