栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot整合websocket后运行测试类报错:javax.websocket.server.ServerContainer not available

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot整合websocket后运行测试类报错:javax.websocket.server.ServerContainer not available

springboot整合websocket,测试类启动报错,

解决方式:在注解中加上webEnvironment参数,此参数的含义,参看官方文档

You can use the webEnvironment attribute of @SpringBootTest to further refine how your tests will run:

MOCK — Loads a WebApplicationContext and provides a mock servlet environment. Embedded servlet containers are not started when using this annotation. If servlet APIs are not on your classpath this mode will transparently fallback to creating a regular non-web ApplicationContext. Can be used in conjunction with @AutoConfigureMockMvc for MockMvc-based testing of your application.
RANDOM_PORT — Loads an ServletWebServerApplicationContext and provides a real servlet environment. Embedded servlet containers are started and listening on a random port.
DEFINED_PORT — Loads an ServletWebServerApplicationContext and provides a real servlet environment. Embedded servlet containers are started and listening on a defined port (i.e from your application.properties or on the default port 8080).
NONE — Loads an ApplicationContext using SpringApplication but does not provide any servlet environment (mock or otherwise).
有4个value可选,根据需要选择即可,其实就是给你的测试类配置了一个真实的servlet环境,并且给这个启动的嵌入式servlet容器一个端口进行监听;

如此就可以结果websocket无法获取的问题

@SpringBootTest(classes = XXX.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_POR

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877767.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号