【发布时间】:2019-01-11 06:16:30
【问题描述】:
我希望根据属性文件中的标志打开/关闭@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));
}
【问题讨论】:
标签: java spring spring-retry