时间紧,主要用于自用,担心以后忘了。

最近使用 spring-boot 写项目,集成了 spring-boot-starter-websocket 和 spring-boot-starter-test;

websocket 配置如下

正常运行 spring-boot 时 websocket 不报错

但是使用单元测试的时候报错

Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/ems/WebSocketConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

去掉 websocket 的配置,单元测试正常

 

@Configuration
public class WebSocketConfig {
   /* @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }*/

}

 

 

另:含有测试类时,给项目打包一般都会失败,删除这些测试类即可。