时间紧,主要用于自用,担心以后忘了。
最近使用 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();
}*/
}
另:含有测试类时,给项目打包一般都会失败,删除这些测试类即可。
本文探讨了在Spring Boot项目中集成WebSocket模块时遇到的单元测试错误问题。当使用spring-boot-starter-websocket和spring-boot-starter-test时,单元测试会抛出关于ServerContainer未可用的异常。通过禁用WebSocket配置,单元测试可以正常运行。
3794

被折叠的 条评论
为什么被折叠?



