更新时间:2021-10-21 15:48:25
可能会有所帮助,请参阅这个答案,感谢 Andres Cespedes Morales :
May be this can help, refer to this answer, thanks to Andres Cespedes Morales:
这条消息说明:你需要在ApplicationContext中配置至少1个ServletWebServerFactory bean ,所以如果你已经有了spring-boot-starter-tomcat,你需要自动配置该bean或手动执行trong>。
This message says: You need to configure at least 1 ServletWebServerFactory bean in the ApplicationContext, so if you already have spring-boot-starter-tomcat you need to either autoconfigure that bean or to do it manually.
因此,在测试中只有2个配置类来加载applicationContext,这些是= {WebsocketSourceConfiguration.class,WebSocketSourceIntegrationTests.class},然后至少在其中一个类中,应该有一个@Bean方法返回所需ServletWebServerFactory的实例。
So, in the test there are only 2 configuration classes to load the applicationContext, these are = { WebsocketSourceConfiguration.class, WebSocketSourceIntegrationTests.class }, then at least in one of these classes there should be a @Bean method returning an instance of the desired ServletWebServerFactory.
确保加载配置类中的所有bean
Make sure to load all the beans within your configuration class
WebsocketSourceConfiguration {
@Bean
ServletWebServerFactory servletWebServerFactory(){
return new TomcatServletWebServerFactory();
}
}
或者还启用自动配置进行类路径扫描和自动配置这些bean。
OR also enable the AutoConfiguration to do a classpath scanning and auto-configuration of those beans.
@EnableAutoConfiguration
WebsocketSourceConfiguration
也可以在Integration Test类中完成。
Can be done also at the Integration Test class.
@EnableAutoConfiguration
WebSocketSourceIntegrationTests
有关更多信息,请查看 SpringBootTest注释文档 https: //docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/SpringBootTest.html
For more information check the SpringBootTest annotation documentation https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/SpringBootTest.html
ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext
Spring Boot Test失败说,由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext
由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext
由于在 run 方法中加载上下文 xml 时缺少 EmbeddedServletContainerFactory bean,因此无法启动 EmbeddedWebApplicationContext
春季启动测试:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext
由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext