Not able to run spring web socket demo
I was facing the same problem. This thread gave me enough clues to solve the problem. Thanks a lot.
SOLUTION:In case you have a Spring MVC Dispatcher Servlet configured in your web.xml and mapped to a url-pattern as shown below
<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/webui/*</url-pattern></servlet-mapping>
Then you have to create the SockJS instance as shown below
var socket = new SockJS('/contextPath/webui/hello');
NOTE: Replace contextPath with your application context path.
This Chrome extension can help you test Websockets.
Also you can have a look at my simple-chat project that uses Spring Boot with Websockets.
Try adding an assets folder inside webapp, where all the stomp and sockjs.js files are made available. Have a look at this example of a running application, that can be run with mvn clean install jetty:run
.
The problem seems to be that either the sockjs is not on the server or some path is wrong. Based on the example on the link, a stomp endpoint can be configured like this:
@EnableWebSocketMessageBrokerpublic class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/portfolio").withSockJS(); }}
Then in javascript the end point can be called like this:
var socket = new SockJS('/spring-websocket-portfolio/portfolio') var stompClient = Stomp.over(socket);
where /spring-websocket-portfolio
is the root deployment path of your application.