我在SpringBoot應用程序的服務中有一個簡單的方法。我使用@Retryable爲該方法設置了重試機制。
我正在嘗試服務中的方法的集成測試,並且當方法拋出異常時不會發生重試。該方法只執行一次。@Retryable在集成測試觸發時未進行重試在Spring Boot應用程序中
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();
}
我不認爲'@ Retryable'被繼承。嘗試將它移動到bean服務方法而不是接口方法 –