2017-08-11 5 views
2

私はSpringブート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

の読み込みに失敗しました。 org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ()org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107) org.springframeworkでorg.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) で org.springframework.test.contextで.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)で(DependencyInjectionTestExecutionListener.java:83) .TestContextManager.prepareTestInstance(TestContextManager.java:242)組織で org.springframework.test.context.junit4.SpringJUnit4ClassRunner $ 1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) でorg.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) で org.springframework.testで.junit.internal.runners.model.ReflectiveCallable.run org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)で(ReflectiveCallable.java:12) .context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)at org.junit.runners.ParentRunner.accessで$ 000(ParentRunner.java:58)org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at org.springframework。 org.junit.runnersでtest.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)で(RunBeforeTestClassCallbacks.java:61) .ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context。 junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore。Javaの:137) で com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) で com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) でorg.springframework: com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) でcom.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) によって引き起こされます.context.ApplicationContextException: リアクティブWebサーバーを起動できません。入れ子になった例外は org.springframework.context.ApplicationContextExceptionです。 にReactWebApplicationContextを開始できません。 ReactWebServerFactoryBeanがありません。 でorg.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:64) でorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ORGで。 org.springframework.boot.SpringApplicationでspringframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:49) でorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) 。 (SpringApplication.java:327) でorg.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:136) でorg.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:177) org.springframework.cloudで org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListenerで.bootstrap.BootstrapApplicationListener.onApplicationEvent org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:65)で(BootstrapApplicationListener.java:99) (SimpleApplicationEventMulticaster .java:167) at org.springframework.boot.contextで org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) でrg.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 。 org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:349)でevent.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73) でorg.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) でorg.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138) でorg.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ORGで org.springframework.context.ApplicationContextException:原因 ReactiveWebServerFactory Beanを行方不明に 開始ReactiveWebApplicationContextにできない以上によって引き起こさ.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ... 25。 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?

hereから完全なデモプロジェクトにアクセスできます。

+0

を使用しているとき、私はあまりにもこのバグを打つよあまりにもこの例外を持っていました。何か進歩しましたか? – ttiurani

+0

これは、スプリングクラウドの依存関係によって引き起こされていることが判明しました。これはまだスプリング5との統合で機能します。[この問題](https://github.com/spring-projects/spring-boot/issues/10017)を参照してください。 )を参照してください。 – Kane

+0

情報ありがとう!私は@SpringBootTestをまったく使用していないのです。なぜなら、私は起動時に他のものも接続する必要があったからです。 – ttiurani

答えて

0

設定プロパティの入力ミスではありませんか?

"spring.main.web-application-type=reactive"

0

私は

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 

代わりの

@SpringBootTest() 
関連する問題