2017-08-11 107 views
2

我有一個使用Spring Webflux通過Spring引導2.0.0.M3的應用程序。將應用程序類型設置爲反應時,無法啓動彈簧引導集成測試

該應用程序在運行時設置爲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) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107) 在 org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) 在 org.springframework .test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) 在 org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44) 在 org.springframework.test.context .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)在 組織.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) 在 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( 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) 在 org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 在org.junit.runners .ParentRunner.run(ParentRunner.java:363) org.springframework.test.context。 junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore。Java的:137)在 com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 在 com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 在 com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 引起:org.springframework .context.ApplicationContextException: 無法啓動反應式Web服務器;嵌套的異常是 org.springframework.context.ApplicationContextException:由於缺少 ReactiveWebServerFactory bean,導致無法啓動ReactiveWebApplicationContext的 bean。在 org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:64) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) 在 有機springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:49) 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) 在 org.springframework.boot.SpringApplication。 refreshContext(SpringApplication.java:386) at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) 在 org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:136) 在 org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:177) 在 org.springframework.cloud .bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:99) 在 org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:65) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster .java:167) at o rg.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) 在 org.springframework.boot.context。 event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73) 在 org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) 在 org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:349) 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.springframework.context.ApplicationContextException:無法 開始ReactiveWebApplicationContext由於缺少 ReactiveWebServerFactory豆.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

原來它是由'spring cloud'的依賴造成的,它依然在與spring 5的集成上工作。參見[this issue](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() 
相關問題