无法在 Spring Boot(Tomcat 应用程序)中从 ServletContext 检索 javax.websocket.server.ServerContainer

Nal*_*aka 5 websocket tomcat8 spring-boot

我有一个使用 spring-boot-starter-tomcat 的 Spring Boot 应用程序。我正在尝试在应用程序类中添加自定义 websocket 端点。

为此,我尝试ServerContainer通过以下方式检索:

 ServerContainer container = (ServerContainer)servletContext.getAttribute(ServerContainer.class.getName());
Run Code Online (Sandbox Code Playgroud)

然而,即使 tomcat 服务器似乎出现在 spring boot 应用程序中,容器也是空的。

有什么方法可以在 Spring Boot 应用程序中初始化 javax.websocket.server.ServerContainer 吗?