我需要 Websockets 在我的应用程序中进行实时更新。所以我找到了这个例子并一步一步地做了here .我完成了教程,最后在启动应用程序时遇到了这个异常:
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: Could not instantiate bean class [org.springframework.web.socket.server.support.DefaultHandshakeHandler]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found
我已经搜索了很多,但我没有找到解决方案。
我希望任何人都可以帮助我,在此先感谢。
最好的问候,帕特里克
最佳答案
我通过添加以下 Maven 依赖项设法解决了这个问题:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>7.0.52</version>
</dependency>
正如 Craig Otis 所指出的,如果您打算部署到 Tomcat,您应该使用 <scope>test</scope>
以确保您不在构建工件中包含依赖项。
关于java - Spring 4 MVC 和 Websockets - 没有合适的默认 RequestUpgradeStrategy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21727286/