我希望根据属性文件中的标志打开/关闭@Recover
方法。如何做到这一点?
实际上,我没有使用注释(@Retryable
/@Recover
),而是使用RetryTemplate
。
解决方案
我使用以下方法作为所有恢复调用的包装方法。
private <T> T genericRecover(RetryContext context) {
if(this.useRecoverMethod) {
return null;
}
throw new RuntimeException(context.getLastThrowable());
}
此处,useRecoverMethod
boolean 标志是从属性文件中读取的。
public Resource<Camera> myRetyableMethod(Long cameraId) {
return retryTemplate.execute(context -> anApiCallMethod(param),
context -> genericRecover(context));
}
最佳答案
这不可能。
但是,当然,您的 @Recover
方法可以根据属性重新引发(或不引发)异常。
关于java - 如何在Spring Retry中打开和关闭@Recover方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54141284/