首页 文章

将应用程序类型设置为反应时,无法启动Spring启动集成测试

提问于
浏览
2

我有一个使用Spring Webflux通过Spring boot 2.0.0.M3的应用程序 .

应用程序在运行时设置为 REACTIVE 类型 .

public static void main(String[] args) {
    SpringApplication application = new SpringApplication(AgentApplication.class);
    application.setWebApplicationType(WebApplicationType.REACTIVE);
    application.run(args);
}

如果运行主应用程序,响应式应用程序工作正常 . 但我在 Spring 季启动集成测试中未能启动此应用程序 .

我宣布测试如下,

@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:无法在org.springframework.test文档中的org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)加载ApplicationContext(DefaultTestContext.java) :107)org.springframework上的org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) . 在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest的org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)中的boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44) SPRIN gJUnit4ClassRunner.java:227)在org.springframework.test.context.junit4.SpringJUnit4ClassRunner $ 1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)位于org.springframework.test.context的org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) . 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)的org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71 .junit.runners.ParentRunner.runChildren(ParentRunner.java:288)org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268) )org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBef) oreTestClassCallbacks.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)at 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)在com.intellij . rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)引起:org.springframework.context.ApplicationContextException:无法启动响应式Web服务器;嵌套异常是org.springframework.context.ApplicationContextException:由于缺少ReactiveWebServerFactory bean,无法启动ReactiveWebApplicationContext . 在org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:64)在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)在org.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)在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)at org .springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:65)org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster .java:139)在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)at atOrg.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)org.springframework.boot.SpringApplication.run(SpringApplication.java:317)位于org.springframework.test.context的org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138) .cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)... 25更多引起:org.springframework.context.ApplicationContextException:由于缺少ReactiveWebServerFactory bean,无法启动ReactiveWebApplicationContext . 在Org.springframework的org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactory(ReactiveWebServerApplicationContext.java:103)org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:87) .boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:61)... 44更多

使用webflux运行spring boot集成测试是否有任何配置问题?

您可以从here访问完整的演示项目 .

2 回答

  • 1

    这不仅仅是配置属性中的拼写错误吗?

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

  • 1

    使用时我也有这个例外

    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    

    代替

    @SpringBootTest()
    

相关问题