javax.websocket.server.ServerContainer not available

原文地址:https://blog.csdn.net/chunjusu2447/article/details/100820520

在SpringBoot项目中集成了WebSocket,在进行单元测试的时候,出现了以下错误:

javax.websocket.server.ServerContainer not available

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

  1.  
    @RunWith(SpringRunner.class)
  2.  
    @SpringBootTest

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

  1.  
    @RunWith(SpringRunner.class)
  2.  
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
原文地址:https://www.cnblogs.com/eyesfree/p/15208735.html