大佬教程收集整理的这篇文章主要介绍了Spring Boot Test失败说,由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
该消息表明: 你需要在ApplicationContext中至少配置1个ServletWebServerFactory bean,因此,如果你已经具有spring-boot-starter-tomcat,则你需要自动配置该bean或手动进行配置。
因此,在测试中,只有2个配置类可以加载applicationContext,它们是= {WebsocketsourceConfiguration.class,WebSocketsourceIntegrationTests.class},然后至少在这些类之一中,应该有一个@Bean方法返回所需实例的实例。 ServletWebServerFactory。
解决方案
确保加载配置类中的所有bean
WebsocketsourceConfiguration {
@Bean
ServletWebServerFactory servletWebServerFactory(){
return new tomcatServletWebServerFactory();
}
}
或还使自动配置能够对这些bean进行类路径扫描和自动配置。
@EnableautoConfiguration
WebsocketsourceConfiguration
也可以在集成测试课程中完成。
@EnableautoConfiguration
WebSocketsourceIntegrationTests
测试类别:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { WebsocketsourceConfiguration.class,WebSocketsourceIntegrationTests.class },webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,properties = {
"websocket.path=/some_websocket_path","websocket.allowedOrigins=*","spring.cloud.stream.default-binder=kafka" })
public class WebSocketsourceIntegrationTests {
private String port = "8080";
@Test
public void testWebSocketStreamsource() throws IOException,InterruptedException {
StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
ClientWebSocketContainer clientWebSocketContainer = new ClientWebSocketContainer(webSocketClient,"ws://localhost:" + port + "/some_websocket_path");
clientWebSocketContainer.start();
WebSocketSession session = clientWebSocketContainer.getSession(null);
session.sendmessage(new Textmessage("foo"));
System.out.println("Done****************************************************");
}
}
我在这里看到过同样的问题,但没有任何帮助。我可以知道我在想什么吗?
我spring-boot-starter-tomcat
在依赖关系层次结构中具有编译时依赖关系。
以上是大佬教程为你收集整理的Spring Boot Test失败说,由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext全部内容,希望文章能够帮你解决Spring Boot Test失败说,由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。