![](/img/trans.png)
[英]Does spring-boot-gradle-plugin moves with the spring-boot version?
[英]@Retryable is not working on Spring-boot-gradle-plugin
我試圖通過添加@Retryable
在我的(spring boot gradle插件)應用程序中添加重試邏輯。
到目前為止,我所做的是:
在課程路徑中添加了最新的入門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();
}
}
但是重試邏輯不起作用。 有人有什么建議嗎?
您需要使用TestRetry
彈簧管理bean,而不是構造自己的對象。 CallRetryClass
應該看起來像:
@Configuration
@EnableRetry
public class CallRetryClass {
@Autowired
private TestRetry testRetry;
public void callRetryMethod() {
testRetry.retryMethod();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.