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(); }
@EnableRetry , , ActionService, Spring Java @Configuration, MyApp. . , , - http://biju-allandsundry.blogspot.com/2014/12/spring-retry-ways-to-integrate-with.html
@EnableRetry
ActionService
@Configuration
MyApp
Biju , , . , , "retryAdvice" bean spring xml, , , aspectj classpath. , , .
<bean id="retryAdvice" class="org.springframework.retry.interceptor.RetryOperationsInterceptor"> </bean> <context:annotation-config /> <aop:aspectj-autoproxy />
Source: https://habr.com/ru/post/1599010/More articles:Angular Google Maps Not Displaying - javascriptMethod not found in class - phpbest way to call a function from an extended class - phpКак получить все последние сообщения коммитов для Xcode Bot "Запустить Script" Триггер? - gitHow to use swift 2 performSelector family of API? - swiftSed template does not produce expected result - sedAccess the "id" value from an example side menu from Iconic frames using AngularJS and - javascriptSwift Adds every second element to an array - arraysBroadcastReceiver fires several times (PROVIDERS_CHANGED_ACTION) - androidUsing JSON content using LINQ / C # - jsonAll Articles