@Retryable does not retry at startup using integration tests In a Spring application to load

I have a simple method in a service in a SpringBoot application. I have a retry mechanism mechanism for this method using @Retryable.
I am trying to run integration tests for a method in a service, and no retries occur when the method throws an exception. The method is executed only once.

public interface ActionService { 

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

}



@Service
public class ActionServiceImpl implements ActionService {

@Override   
public void perform() throws Exception() {

   throw new Exception();
  } 
}



@SpringBootApplication
@Import(RetryConfig.class)
public class MyApp {

public static void main(String[] args) throws Exception {
    SpringApplication.run(MyApp.class, args);
  }
}



@Configuration
@EnableRetry
public class RetryConfig {

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

}



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

@Autowired
private ActionService actionService;

public void testAction() {

  actionService.perform();

}
+4
source share
2 answers

@EnableRetry , , ActionService, Spring Java @Configuration, MyApp. . , , - http://biju-allandsundry.blogspot.com/2014/12/spring-retry-ways-to-integrate-with.html

+4

Biju , , . , , "retryAdvice" bean spring xml, , , aspectj classpath. , , .

    <bean id="retryAdvice"
    class="org.springframework.retry.interceptor.RetryOperationsInterceptor">
</bean>

<context:annotation-config />
<aop:aspectj-autoproxy />
0

Source: https://habr.com/ru/post/1599010/


All Articles