2016-08-18 63 views
2

我试图通过添加@Retryable在我的(spring boot gradle插件)应用程序中添加重试逻辑。@Retryable在Spring-boot-gradle-plugin上不起作用

是我迄今所做的:

增加了最新的入门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(); 
    } 
} 

但是重试逻辑不起作用。有没有人有任何建议?

回答

0

您需要使用弹簧管理的豆TestRetry而不是构建自己的对象。 CallRetryClass应该看起来像:

@Configuration 
@EnableRetry 
public class CallRetryClass { 

    @Autowired 
    private TestRetry testRetry; 

    public void callRetryMethod() { 
     testRetry.retryMethod(); 
    } 
}