簡體   English   中英

@Retryable在Spring-boot-gradle-plugin上不起作用

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM