繁体   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