Spring 重试 - 异常问题并重试

Spring Retry - Exception problem and retries

我们如何在 @Retryable 方法的同一块中捕获两个不同的异常(例如来自 .lang.io 包)。一个,我们 return 一个 IOException,另一个我们重试该方法。

@Retryable(value = {Exception.calss } ,maxAttempts = 3, backoff = @Backoff(delay = 3000))
public String getInfo() {
    try {
        //here we have an executive code that may have an IOException
    } catch(Exception ex) {
        //And here i would catch the Exception 
        throw new Exception();
    }   
}

可以使用注解的include参数来处理多种异常:

@Retryable(
    include = { IllegalAccessException.class, IOException.class }, 
    maxAttempts = 3, 
    backoff = @Backoff(delay = 3000))
public String getInfo() {
    // some code
}