Spring Boot 2.0.0.M3 経由で Spring Webflux を使用するアプリケーションがあります。
アプリケーションは、実行時にREACTIVEタイプとして設定されます。
public static void main(String[] args) {
SpringApplication application = new SpringApplication(AgentApplication.class);
application.setWebApplicationType(WebApplicationType.REACTIVE);
application.run(args);
}
メイン アプリケーションを実行している場合、リアクティブ アプリは正常に動作します。しかし、春のブート統合テストでこのアプリを起動できませんでした。
以下のようにテストを宣言しました。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"spring.main.webApplicationType=reactive"})
@ActiveProfiles("integTest")
public class NoteHandlerTest {
@Autowired
private WebTestClient webClient;
@Test
public void testGetNoteNotFound() throws Exception {
this.webClient.get().uri("/note/request/{id}", "nosuchid").accept(MediaType.APPLICATION_JSON_UTF8)
.exchange().expectStatus().isOk();
}
}
テスト ケースを実行すると、以下のエラーが発生しました。
java.lang.IllegalStateException: ApplicationContext のロードに失敗しました
intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) com.intellij.rt.execution. junit.JUnitStarter.main(JUnitStarter.java:70) 原因: org.springframework.context.ApplicationContextException: リアクティブ Web サーバーを起動できません。ネストされた例外は org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory Bean です。org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:64) で org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) で org.springframework.boot.ReactiveWebServerFactory Bean が見つからないため、ReactiveWebApplicationContext を開始できません。 org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:103) で org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:87) で org.springframework .boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:61) ... 44 詳細
webflux でスプリング ブート統合テストを実行するための構成上の問題はありますか?
ここから完全なデモ プロジェクトにアクセスできます。