Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 4 MVC and Websockets - No suitable default RequestUpgradeStrategy

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:

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

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

I hope anyone can help me, thanks in advance.

best regards, patrick

like image 579
pat Avatar asked Feb 12 '14 11:02

pat


2 Answers

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

<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.

like image 134
Balázs Palkó Avatar answered Oct 03 '22 21:10

Balázs Palkó


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

like image 32
darkconeja Avatar answered Oct 03 '22 23:10

darkconeja