title: websockets with Tomcat 8 and Spring 4 ClassCastException before handler is invoked
body: <p>I am trying to get a simple websocket to work to integrate into my application. However I have not been able to get it to work with the Spring API's, with a ClassCastException somewhere before my handler is invoked trying to convert a Tomcat type to a javax object. If I just use Tomcat directly without Spring (so the javax.websocket objects and annotations) it works perfectly, so I am really not sure why there is an issue with Spring.</p>
  
  <pre><code>08-May-2014 01:10:12.048 SEVERE [http-nio-8084-exec-88] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/WebsocketSpringTest] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8084/WebsocketSpringTest/socket; nested exception is java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to javax.websocket.server.ServerContainer] with root cause
  java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to javax.websocket.server.ServerContainer
  at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getContainer(AbstractStandardUpgradeStrategy.java:67)
  </code></pre>
  
  <p>TestSocket.java</p>
  
  <pre><code>import org.springframework.web.socket.WebSocketHandler;
  public class TestSocket implements WebSocketHandler {
      ...
  </code></pre>
  
  <p>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;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;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>dispatcher-servlet.xml</p>
  
  <pre><code>&lt;context:component-scan base-package="com.willnewbery.websocketspringtest" /&gt;
  &lt;context:annotation-config /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
          p:prefix="/WEB-INF/views/" p:suffix=".jsp" /&gt;
  &lt;websocket:handlers&gt;
      &lt;websocket:mapping path="/socket" handler="socket"/&gt;
  &lt;/websocket:handlers&gt;
  &lt;bean id="socket" class="com.willnewbery.websocketspringtest.TestSocket"/&gt;
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;properties&gt;
      &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;spring.version&gt;4.0.4.RELEASE&lt;/spring.version&gt;
      &lt;tomcat.version&gt;8.0.3&lt;/tomcat.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;!--javax--&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
          &lt;version&gt;7.0&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.websocket&lt;/groupId&gt;
          &lt;artifactId&gt;javax.websocket-api&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--spring--&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-websocket&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--tomcat--&gt;
  &lt;/dependencies&gt;
  </code></pre>