@Retryable未被触发

Joe*_*sey 4 spring spring-retry

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

Application.java:

@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
//...
Run Code Online (Sandbox Code Playgroud)

这是在Service类中:

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();
}    
Run Code Online (Sandbox Code Playgroud)

Gar*_*ell 10

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

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