我使用spring-retry为我的业务逻辑提供重试策略。我有接口和实现它的服务
public interface MyInterface {
@Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L))
void doSth() throws Exception;
@Recover
void recoverIfFailed(Exception e);
}
@Service
public class MyService implements MyInterface {
public void doSth() throws Exception {
throw new Exception();
}
public void recoverIfFailed(Exception e) {
System.out.println("Recovered!");
}
}在这种配置中,一切正常工作。但是,我不明白为什么不能像这样将@Recovery注释移到接口实现上:
@Service
public class MyService implements MyInterface {
@Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L)) // -- this is working
public void doSth() throws Exception {
throw new Exception();
}
@Recover // -- this is not working!
public void recoverIfFailed(Exception e) {
System.out.println("Recovered!");
}
}我真的不想在接口中公开我的恢复方法(因为它似乎是我的内部逻辑),但由于这个问题,我不能。有人能告诉我什么是问题吗?
发布于 2018-10-11 17:12:58
我提交了一个打开拉请求以修复此问题。
作为一种解决方案,使用@EnableRetry(proxyTargetClass = true)。
https://stackoverflow.com/questions/52765023
复制相似问题