java - 尽管在方法声明中声明了已检查的异常,但在 Spring Retry 中抛出了 UndeclaredThrowableException
问题描述
编辑:我仔细阅读了链接的主题(Getting UndeclaredThrowableException 而不是我自己的异常),但它没有回答我的问题 - 该票建议在我已经做过的拦截方法中声明检查的异常。
我正在尝试使用 Spring Retry 机制并希望在 resolve 方法中抛出我的自定义检查异常,但它因 UndeclaredThrowableException 而失败。这是我所做的:
- 我已经声明了我的自定义 RuntimeException(这表明我需要重试):
public class RestCallRetryException extends RuntimeException
- 然后我在以下方法的实现中抛出这个运行时异常:
@Retryable(value = RestCallRetryException.class, maxAttempts = 2) InquiryResponse postInquiry(InquiryRequest inquiryRequest) throws RestCallException;
- 我已经声明了重试方法来处理它:
@Recover InquiryResponse recover(RestCallRetryException e) throws RestCallException;
- 如您所见,我还有 RestCallException,它是在恢复中抛出的已检查异常:
public class RestCallException extends Exception
我在recover(RestCallRetryException e) 的实现中抛出RestCallException 并得到UndeclaredThrowableException。我不明白为什么会这样。如果我没有声明标有 @Retryable (postInquiry) 的方法会引发 RestCallException,我会理解这种情况——但这一切都已声明,正如您在我的代码片段中看到的那样。我在这里想念什么?
解决方案
推荐阅读
- julia - 定义中的评估
- scala - 如何将字符串列转换为列表
- java - Java中的十六进制字符串到二进制
- javascript - 单击外部关闭下拉菜单仅在单击外部时有效
- api - SoftLayer_User_Customer_ApiAuthentication::getUser 失败并出现异常
- python - 是否有更快的方法来计算多列中的值,不包括同一行上的重复值?
- swift - Bundle.main.path 返回 nil
- php - 使用空字符串值传递的 $_GET 变量
- ruby - 理解 Ruby 中的字符串附加
- python-3.x - 将数据从 python 写入 redshift 时出错 - 日期格式无效 - 长度必须为 10 或更多