这个问题来自
relevant details。在springboot项目中使用websocket和stomp时,出现No 'javax.websocket.server.ServerContainer' ServletContext attribute
错误。
// org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.java
protected ServerContainer getContainer(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
String attrName = "javax.websocket.server.ServerContainer";
ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName);
// container is null
Assert.notNull(container, "No 'javax.websocket.server.ServerContainer' ServletContext attribute. " +
"Are you running in a Servlet container that supports JSR-356?");
return container;
}
我尝试了以下解决方案,但无济于事。
// layout of project
projectname
--src/main/webapp/WEB-INF/web.xml // created manually
--module1/src/main/java/Application.java // Class with annotiation @SpringBootApplication
--module2/src/main/java/...
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<absolute-ordering>
<name>spring_web</name>
</absolute-ordering>
</web-app>