Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.3.15.jar:5.3.15]
at org.springframework.web.socket.server.standard.ServerEndpointExporter.afterPropertiesSet(ServerEndpointExporter.java:107) ~[spring-websocket-5.3.15.jar:5.3.15]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15]
... 100 common frames omitted
原因:springboot内带tomcat,tomcat中的websocket会有冲突出现问题,因此跳过test编译打包
解决方式
//@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
上面的方式打包没问题 ,但是ws连接就连接不了。
第二个解决方式,加红色部分。不用注释@bean,就能正常打包和连接了
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class SpringbootApplicationTests {
@Test
void contextLoads() {
}
}