springboot重试机制失败后不能回调@Recover 注解的方法
错误代码如下:
@Retryable(value= {RemoteAccessException.class},maxAttempts = 3,backoff =@Backoff(delay = 5000L,multiplier = 1))
public RestUtils call() throws Exception {
System.out.println("do something...");
throw new RemoteAccessException("RPC调用异常");
}
@Recover
public void recover(RemoteAccessException e) {
System.out.println(e.getMessage());
System.out.println("1233143212");
}
@Retryable注解的方法,当有返回值(RestUtils)时,是不会触发到@Recover注解的方法。改成下边的方法就可以了:
@Retryable(value= {RemoteAccessException.class},maxAttempts = 3,backoff = @Backoff(delay = 5000L,multiplier = 1))
public void call() throws Exception {
System.out.println("do something...");
throw new RemoteAccessException("RPC调用异常");
}
@Recover
public void recover(RemoteAccessException e) {
System.out.println(e.getMessage());
System.out.println("1233143212");
}