Spring Retry-异常问题和重试次数



如何在@Retryable方法的同一块中捕获两个不同的异常(例如来自.lang.io包(。一个是返回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
}

最新更新