Java Spring 4 MVC 和 Websockets - 没有合适的默认 RequestUpgradeStrategy

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21727286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:21:17  来源:igfitidea点击:

Spring 4 MVC and Websockets - No suitable default RequestUpgradeStrategy

javaspringhibernatespring-mvcwebsocket

提问by pat

I need Websockets for real-time updates in my application. So i found this example and did it step by step here. I went through the tutorial and finally i got this exception when starting the application:

我需要 Websockets 在我的应用程序中进行实时更新。所以我找到了这个例子并在这里一步一步地做到。我完成了教程,最后在启动应用程序时遇到了这个异常:

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

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'org.springframework.web.socket.server.support.DefaultHandshakeHandler#0':bean实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 bean 类 [org.springframework.web.socket.server.support.DefaultHandshakeHandler]:构造函数抛出异常;嵌套异常是 java.lang.IllegalStateException:找不到合适的默认 RequestUpgradeStrategy

I have searched a lot, but i didn't find a solution.

我已经搜索了很多,但我没有找到解决方案。

I hope anyone can help me, thanks in advance.

我希望任何人都可以帮助我,在此先感谢。

best regards, patrick

最好的问候,帕特里克

回答by Prabhat

I am also facing this problem, got across a link see if this is helpful https://github.com/rstoyanchev/spring-websocket-portfolio/issues/21

我也面临这个问题,通过一个链接看看这是否有帮助https://github.com/rstoyanchev/spring-websocket-portfolio/issues/21

回答by Balázs Palkó

I managed to resolve this issue by adding the following maven dependency:

我设法通过添加以下 Maven 依赖项来解决此问题:

<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-websocket</artifactId>
   <version>7.0.52</version>
</dependency>

As pointed by Craig Otis, if you're planning on deploying to Tomcat anyway, you should use <scope>test</scope>to ensure you don't include the dependency in your build artifact.

正如 Craig Otis 所指出的,如果您打算无论如何都部署到 Tomcat,您应该使用<scope>test</scope>以确保您的构建工件中不包含依赖项。

回答by raymond

The exception means DefaultHandshakeHandler cannot find a supported servers (e.g. Tomcat 7 & 8, Jetty 9). Refer to the javadoc here.

异常意味着 DefaultHandshakeHandler 找不到支持的服务器(例如 Tomcat 7 & 8、Jetty 9)。请参阅此处的 javadoc 。

回答by Tk421

The version of Tomcat that you are using is too old.

您使用的 Tomcat 版本太旧。

Upgrade tomcat. http://tomcat.apache.org/download-70.cgi

升级tomcat。 http://tomcat.apache.org/download-70.cgi

回答by darkconeja

I lost a lot of time digging out for the solution, what i found was that spring websocket will only run over Tomcat 7.0.47+, Jetty 9.1+, GlassFish 4.1+, WebLogic 12.1.3+, and Undertow 1.0+ (and WildFly 8.0+)according to spring's documentation shown here http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html, so try updating your app server

我花了很多时间寻找解决方案,我发现 spring websocket 只能在Tomcat 7.0.47+、Jetty 9.1+、GlassFish 4.1+、WebLogic 12.1.3+ 和 Undertow 1.0+(和 WildFly 8.0+)根据此处显示的 spring 文档 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html,因此请尝试更新您的应用服务器

回答by Munish Chandel

I was facing this issue while running websockets in IDE using embedded Jetty, fixed this after adding the below dependencies to pom.xml

我在使用嵌入式 Jetty 在 IDE 中运行 websockets 时遇到了这个问题,在将以下依赖项添加到 pom.xml 后修复了这个问题

            <dependency>
                <groupId>org.eclipse.jetty.websocket</groupId>
                <artifactId>websocket-client</artifactId>
                <version>9.3.4.RC0</version>
                <!--<scope>test</scope>-->
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty.websocket</groupId>
                <artifactId>websocket-server</artifactId>
                <version>9.3.4.RC0</version>
                <!--<scope>test</scope>-->
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-client</artifactId>
                <version>9.3.4.RC0</version>
                <!--<scope>test</scope>-->
            </dependency>