我正在尝试通过添加@Retryable在我的(spring boot gradle plugin)应用程序中添加重试逻辑。
到目前为止,我所做的是:
在类路径中添加最新的starter aop:
classpath(group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '1.4.0.RELEASE')重试类:
@Component
@EnableRetry
public class TestRetry {
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
public void retryMethod() {
throw new RunTimeException("retry exception");
}
}测试逻辑:
@Configuration
@EnableRetry
public class CallRetryClass {
public void callRetryMethod() {
TestRetry testRetry = new TestRetry();
testRetry.retryMethod();
}
}但是重试逻辑不起作用。有人有什么建议吗?
发布于 2017-03-14 20:18:47
您需要使用TestRetry的spring托管bean,而不是构造您自己的对象。CallRetryClass应该如下所示:
@Configuration
@EnableRetry
public class CallRetryClass {
@Autowired
private TestRetry testRetry;
public void callRetryMethod() {
testRetry.retryMethod();
}
}https://stackoverflow.com/questions/39011115
复制相似问题