title: Failed to start spring boot integration test when setting the application type as reactive
body: <p>I have an application using Spring Webflux via Spring boot 2.0.0.M3.</p>
  
  <p>The application is set as <strong>REACTIVE</strong> type when running it.</p>
  
  <pre><code>public static void main(String[] args) {
      SpringApplication application = new SpringApplication(AgentApplication.class);
      application.setWebApplicationType(WebApplicationType.REACTIVE);
      application.run(args);
  }
  </code></pre>
  
  <p>The reactive app works fine if running the main application. But I failed to start this app in my spring boot integration test.</p>
  
  <p>I declared the test as below,</p>
  
  <pre><code>@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();
  }
  
  }
  </code></pre>
  
  <p>I got below error when running the test case,</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Failed to load ApplicationContext</p>
    
    <p>at
    org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
      at
    org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107)
      at
    org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
      at
    org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
      at
    org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
      at
    org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)
      at
    org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)  at
    org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
      at
    org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at
    org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
      at
    org.springframework.test.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)   at
    org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)  at
    org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at
    org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.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)   at
    com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at
    com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
      at
    com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at
    com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    Caused by: org.springframework.context.ApplicationContextException:
    Unable to start reactive web server; nested exception is
    org.springframework.context.ApplicationContextException: Unable to
    start ReactiveWebApplicationContext due to missing
    ReactiveWebServerFactory bean.    at
    org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:64)
      at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
      at
    org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:49)
      at
    org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
      at
    org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
      at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
      at
    org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:136)
      at
    org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:177)
      at
    org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:99)
      at
    org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:65)
      at
    org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
      at
    org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      at
    org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
      at
    org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
      at
    org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
      at
    org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:349)
      at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
      at
    org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138)
      at
    org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
      at
    org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
      ... 25 more Caused by:
    org.springframework.context.ApplicationContextException: <strong>Unable to
    start ReactiveWebApplicationContext due to missing
    ReactiveWebServerFactory bean.</strong>  at
    org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:103)
      at
    org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:87)
      at
    org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:61)
      ... 44 more</p>
  </blockquote>
  
  <p>Does it have any configuration issue to run spring boot integration test with webflux?</p>
  
  <p>You can access the complete demo project from <a href="https://github.com/zxkane/spring-boot-webflux-router-issue/tree/spring-boot-test-reactive" rel="nofollow noreferrer">here</a>.</p>