user3451476 user3451476 - 1 month ago 61
Java Question

@Retryable not making retries when triggered by Integration tests In A Spring Boot Application

I have a simple method in a Service in a SpringBoot Application. I have the retry mechanism setup for that method using @Retryable.

I am trying integration tests for the method in the service and the retries are not happening when the method throws an exception. The method gets executed only once.

public interface ActionService {

@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
public void perform() throws Exception;


public class ActionServiceImpl implements ActionService {

public void perform() throws Exception() {

throw new Exception();

public class MyApp {

public static void main(String[] args) throws Exception {, args);

public class RetryConfig {

public ActionService actionService() { return new ActionServiceImpl(); }


@SpringApplicationConfiguration( classes= {MyApp.class})
@IntegrationTest({"server.port:0", "management.port:0"})
public class MyAppIntegrationTest {

private ActionService actionService;

public void testAction() {




Your annotation @EnableRetry is at the wrong place, instead of putting it on the ActionService interface you should place it with a Spring Java based @Configuration class, in this instance with the MyApp class. With this change the retry logic should work as expected. Here is a blog post that I had written on if you are interested in more details -