Spring Retry - 异常问题和重试

Med*_*Med 4 java spring exception spring-retry spring-boot

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

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

Nik*_*las 9

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

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