@Retryable未被触发

时间:2017-01-26 22:05:32

标签: spring spring-retry

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

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();
}    

1 个答案:

答案 0 :(得分:9)

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

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