![](/img/trans.png)
[英]Intellij - Spring Retry @Recover method marked as unused
[英]How to switch on and off @Recover method in Spring Retry?
我希望基于属性文件中的标志打开/关闭@Recover
方法。 怎么做?
实际上,我没有使用批注( @Retryable
/ @Recover
),而是使用RetryTemplate
。
解
我正在使用以下方法作为所有恢复调用的包装方法。
private <T> T genericRecover(RetryContext context) {
if(this.useRecoverMethod) {
return null;
}
throw new RuntimeException(context.getLastThrowable());
}
这里, useRecoverMethod
布尔标志是从属性文件中读取的。
public Resource<Camera> myRetyableMethod(Long cameraId) {
return retryTemplate.execute(context -> anApiCallMethod(param),
context -> genericRecover(context));
}
这是不可能的。
但是,当然,您的@Recover
方法可以基于该属性重新引发(或不引发)异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.