简体   繁体   English

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

[英]@Retryable is not working on Spring-boot-gradle-plugin

I'm trying to add retry logic in my (spring boot gradle plugin) application by adding @Retryable . 我试图通过添加@Retryable在我的(spring boot gradle插件)应用程序中添加重试逻辑。

What i have done so far: 到目前为止,我所做的是:

Added latest starter aop in class path: 在课程路径中添加了最新的入门aop:

classpath(group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '1.4.0.RELEASE')

Retry class: 重试类:

@Component
@EnableRetry
public class TestRetry {
    @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
    public void retryMethod() {
        throw new RunTimeException("retry exception");
    }
}

Test logic: 测试逻辑:

@Configuration
@EnableRetry
public class CallRetryClass {
    public void callRetryMethod() {
        TestRetry testRetry = new TestRetry();
        testRetry.retryMethod();
    }
}

But the retry logic is not working. 但是重试逻辑不起作用。 Do anyone have any suggestion? 有人有什么建议吗?

You need to use spring-managed bean of TestRetry instead of constructing your own object. 您需要使用TestRetry弹簧管理bean,而不是构造自己的对象。 CallRetryClass should look like: 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