2016-08-18 59 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(); 
    } 
}