2

I'm trying to add retry logic in my (spring boot gradle plugin) application by adding @Retryable.

What i have done so far:

Added latest starter aop in class path:

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?

Chacko
  • 1,506
  • 1
  • 20
  • 42
Minh
  • 424
  • 3
  • 12

1 Answers1

1

You need to use spring-managed bean of TestRetry instead of constructing your own object. CallRetryClass should look like:

@Configuration
@EnableRetry
public class CallRetryClass {

    @Autowired
    private TestRetry testRetry;

    public void callRetryMethod() {
        testRetry.retryMethod();
    }
}
Chacko
  • 1,506
  • 1
  • 20
  • 42