问题描述
我使用的是 Spring Boot v2.3.8.RELEASE 和嵌入式 Apache Tomcat/9.0.41。
我必须在 Spring 中使用 javax.websocket,但我面临的问题是如果没有 ServerEndpointExporter bean,我无法使用 javax.websocket。
所以我只是添加了配置:
@Configuration
@EnableWebSocket
public class WebSocketConfiguration {
@Bean
public ServerEndpointExporter serverEndpointExporter(ServletContext servletContext) {
ServerEndpointExporter serverEndpointExporter = new ServerEndpointExporter();
serverEndpointExporter.setServerContainer((ServerContainer) servletContext
.getAttribute("javax.websocket.server.ServerContainer"));
return serverEndpointExporter; }
}
在创建 bean 的时候,我可以看到 ServletContext 的所有属性:
所以在创建后我得到了错误:
javax.websocket.server.ServerContainer 不可用
还有一些魔法,我有相同版本的 spring 和 tomcat 的类似模拟项目,它可以工作:
我一直试图找到任何解决方案,但没有任何帮助。可能是什么原因?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)