我在 SpringBoot 应用程序的服务中有一个简单的方法。我使用@Retryable 为该方法设置了重试机制。
我正在尝试对服务中的方法进行集成测试,并且当方法抛出异常时重试不会发生。该方法只执行一次。
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();
}