title: Spring websocket getting 404 not found
body: <p>I am trying to create an websocket endpoint with spring. But Whenever I am trying to connect from the client end, I get 404. I also have an Java implementation with </p>
  
  <pre><code>@ServerEndpoint(value = "/websocket")
  </code></pre>
  
  <p>which works good. Below is the code of my spring implementation which is not working. What am I doing wrong here?</p>
  
  <pre><code>package com.tlab.endpoint;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.socket.WebSocketHandler;
  import org.springframework.web.socket.config.annotation.EnableWebSocket;
  import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
  import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
  
  @Configuration
  @EnableWebSocket
  public class WebSocketConfig implements WebSocketConfigurer {
  
      @Override
      public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
          registry.addHandler(socketHandler(),"/socket");;
      }
  
      @Bean
      public WebSocketHandler socketHandler() {
          return new SocketHandler();
      }
  
  }
  </code></pre>
  
  <p>below is the Handler</p>
  
  <pre><code>package com.tlab.endpoint;
  
  import org.springframework.web.socket.TextMessage;
  import org.springframework.web.socket.WebSocketSession;
  import org.springframework.web.socket.handler.TextWebSocketHandler;
  
  
  public class SocketHandler extends TextWebSocketHandler {
  
      @Override
      public void handleTextMessage(WebSocketSession session, TextMessage message) {
  
      }
  
  }
  </code></pre>
  
  <p>In the client side code I tried all diff possible combination </p>
  
  <p>with /socket in handler</p>
  
  <pre><code>var websocket = new WebSocket("ws://localhost:8080/tsim/socket");
  var websocket = new WebSocket("ws://localhost:8080/tsim/socket");
  var websocket = new WebSocket("ws://localhost:8080/tsim/rest/socket");
  </code></pre>
  
  <p>with /rest/socket in handler</p>
  
  <pre><code>var websocket = new WebSocket("ws://localhost:8080/tsim/rest/socket");
  </code></pre>
  
  <p>where tsim is my contextroot. Everything throws the below error</p>
  
  <pre><code>WebSocket connection to 'ws://localhost:8080/tsim/socket' failed: Error during WebSocket handshake: Unexpected response code: 404.
  </code></pre>
  
  <p>I didn't get any compilation and deployment errors. I used tomcat 8.0 and below is the dispatcher servlet configuration.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:int="http://www.springframework.org/schema/integration"
         xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
         xmlns:batch="http://www.springframework.org/schema/batch"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xmlns:websocket="http://www.springframework.org/schema/websocket"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
              http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
              http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
              http://www.springframework.org/schema/websocket
          http://www.springframework.org/schema/websocket/spring-websocket.xsd"
          &gt;
  
      &lt;import resource="classpath*:web-db-spring.xml"/&gt;
  
       &lt;context:component-scan base-package="com.traderslab.nseb,com.tlab.endpoint"/&gt;
  
       &lt;aop:aspectj-autoproxy/&gt;
  
      &lt;mvc:annotation-driven&gt;
          &lt;mvc:message-converters&gt;
              &lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
                  &lt;property name="prefixJson" value="false"/&gt;
                  &lt;property name="supportedMediaTypes" value="application/json"/&gt;
                  &lt;property name="objectMapper"&gt;
                      &lt;bean class="com.fasterxml.jackson.databind.ObjectMapper"&gt;
                          &lt;property name="serializationInclusion" value="NON_NULL"/&gt;
                      &lt;/bean&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
              &lt;bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/&gt;
          &lt;/mvc:message-converters&gt;
      &lt;/mvc:annotation-driven&gt;
  
      &lt;mvc:default-servlet-handler/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>below is my web.xml</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/classes/dispatcher-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>