javax.websocket.server.ServerContainer not available

置顶个交流群

文章觉得海星的话,可以来群里找桃子交流技术或者普通乱聊= =

挂群: 820080257

1 问题

springboot 单元测试报错:

javax.websocket.server.ServerContainer not available

2 流程

单元测试类的原注解是这样的:

@RunWith(SpringRunner.class)
@SpringBootTest

经查阅资料,得知SpringBootTest在启动的时候不会启动服务器,所以WebSocket自然会报错,这个时候需要添加选项webEnvironment,以便提供一个测试的web环境。如下:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

Guess you like

Origin blog.csdn.net/weixin_46017976/article/details/118903605