pat
pat

Reputation: 119

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

Upvotes: 11

Views: 20531

Answers (7)

Rence Abishek
Rence Abishek

Reputation: 413

In Addition,

If you are using gradle, You should add below dependency in build.gradle

compile 'org.projectreactor:reactor-spring:1.0.1.RELEASE'

Upvotes: 0

Balázs Palkó
Balázs Palkó

Reputation: 641

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.

Upvotes: 30

Munish Chandel
Munish Chandel

Reputation: 3702

I was facing this issue while running websockets in IDE using embedded Jetty, fixed this after adding the below dependencies to 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>

Upvotes: 6

darkconeja
darkconeja

Reputation: 348

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

Upvotes: 3

Tk421
Tk421

Reputation: 6418

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

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

Upvotes: 2

raymond
raymond

Reputation: 21

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

Upvotes: 1

Prabhat
Prabhat

Reputation: 850

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

Upvotes: 1

Related Questions