在使用Spring MVC的websocket配置时 Tomcat启动报错
错误信息如下:
[ERROR][localhost-startStop-1] org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:502) Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.server.support.WebSocketHandlerMapping#0': Cannot resolve reference to bean 'org.springframework.web.socket.server.support.WebSocketHttpRequestHandler#0'
while setting bean property 'urlMap' with key [/websocket]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.server.support.WebSocketHttpRequestHandler#0': Cannot resolve reference to bean
'org.springframework.web.socket.server.support.DefaultHandshakeHandler#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.server.support.DefaultHandshakeHandler#0':
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.socket.server.support.DefaultHandshakeHandler]: Constructor threw exception; nested exception is java.lang.IllegalStateException:
No suitable default RequestUpgradeStrategy found
原因是因为Tomcat版本太老,之前一直用的是apache-tomcat-7.0.42,Spring官网说要用Tomcat7.0.47+的版本(https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#websocket-server),果断升级Tomcat版本为apache-tomcat-7.0.82,问题解决。
附原文:
Currently the list includes WebSocket runtimes such as Tomcat 7.0.47+, Jetty 9.1+, GlassFish 4.1+, WebLogic 12.1.3+, and Undertow 1.0+ (and WildFly 8.0+).
除非注明,否则均为李锋镝的博客原创文章,转载必须以链接形式标明本文链接