繁体   English   中英

如何在Spring Retry中打开和关闭@Recover方法?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM