【发布时间】:2021-11-10 16:09:04
【问题描述】:
以下重试工作正常。在 3 次尝试失败后调用恢复方法
@Retryable(value = MyException.class)
public String getSomething(String performanceId) {
String s = "test";
...
throw new MyException("test", new RuntimeException());
...
return s;
}
@Recover
public String recover(MyException exception, String performanceId) {
log.info("In recover method!!!!!!!!!!!!!!!!!!");
return "test";
}
但是当我更改返回类型时,将不会调用以下恢复方法。你能告诉我为什么以及如何解决这个问题吗?非常感谢!
@Retryable(value = MyException.class)
public MyOwnType getSomething(String performanceId) {
MyOwnType s = new MyOwnType();
...
throw new MyException("test", new RuntimeException());
...
return s;
}
@Recover
public MyOwnType recover(MyException exception, String performanceId) {
log.info("In recover method!!!!!!!!!!!!!!!!!!");
return new MyOwnType();
}
public class MyOwnType implements Serializable {
...
}
编辑: 我忘了提到我也在抛出一个自定义异常
public class MyException extends RuntimeException {
private static final long serialVersionUID = 1L;
public MyException(String message, Throwable cause) {
super(message, cause);
}
}
【问题讨论】:
标签: java spring spring-retry