title: ClassCastException with Spring-Websocket because of Tomcat ServerContainer
body: <p>While trying to connect to Spring Websocket with SockJS, I am getting an error</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; 
  nested exception is org.springframework.web.socket.sockjs.SockJsException: 
  Uncaught failure in SockJS request, uri=http://localhost:8083//subscribe/info/771/nay07fet/websocket; 
  nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException:
  WebSocket handshake failure; nested exception is java.lang.ClassCastException: 
  org.eclipse.jetty.websocket.jsr356.server.ServerContainer cannot be cast 
  to org.apache.tomcat.websocket.server.WsServerContainer
  </code></pre>
  
  <p>From online I figured out that I shall disable Tomcat in Classpath to overcome it, but no matter how I try, I can not get rid of Tomcat. </p>
  
  <p>How I can reliably exclude tomcat from any project? Note that I found it in several places.</p>
  
  <p>My current Dependency tree is here: <a href="http://pastebin.com/pH1iQejd" rel="nofollow">http://pastebin.com/pH1iQejd</a> 
  and it contains some tomcat. <strong>I need to get rid of everything that might cause that type confusion.</strong></p>
  
  <p>Here's my gradle.build (I tried some exlcudes but without success):</p>
  
  <pre><code>group 'com.company'
  if (!hasProperty("buildNumber")) {
      version "1.0.0-SNAPSHOT"
  } else {
      version "1.0.${buildNumber}-SNAPSHOT"
  }
  
  
  
  buildscript {
      repositories {
          mavenCentral()
          maven {
              url "https://plugins.gradle.org/m2"
          }
  
  
      }
      dependencies {
          classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
          classpath("gradle.plugin.com.boxfuse.client:flyway-release:4.0.1")
          classpath fileTree(dir: 'libs', include: '*.jar')
          classpath fileTree(dir: 'src/main/resources/db/migration', include: '*.sql')
      }
  }
  
  
  apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'idea'
  apply plugin: 'spring-boot'
  
  sourceCompatibility = 1.8
  targetCompatibility = 1.8
  
  repositories {
      mavenCentral()
      maven {
          url "https://plugins.gradle.org/m2"
      }
  
  }
  
  
  dependencies {
      // tag::jetty[]
      compile("org.springframework.boot:spring-boot-starter-web") {
          exclude module: "spring-boot-starter-tomcat"
          exclude module: 'spring-boot-starter-logging'
      }
      compile("org.springframework.boot:spring-boot-starter-jetty") {
          exclude module: "spring-boot-starter-tomcat"
          exclude module: 'spring-boot-starter-logging'
      }
      // end::jetty[]
      // tag::actuator[]
      compile("org.springframework.boot:spring-boot-starter-actuator")
      compile("org.springframework.boot:spring-boot-starter-data-jpa"){
          exclude module: "spring-boot-starter-tomcat"
          exclude module: 'spring-boot-starter-logging'
      }
      compile("org.springframework.boot:spring-boot-starter-data-rest")
      compile("org.springframework.boot:spring-boot-starter-websocket")
      // http://mvnrepository.com/artifact/org.springframework.security/spring-security-core
      compile group: 'org.springframework.security', name: 'spring-security-core', version: '4.1.0.RELEASE'
  
      compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
      compile group: 'com.google.code.gson', name: 'gson', version: '2.5'
      compile group: 'com.rabbitmq', name: 'amqp-client', version: '3.5.6'
      compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
      compile group: 'com.google.guava', name: 'guava', version: '18.0'
      compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
      compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
      compile("org.springframework:spring-messaging")
      compile 'org.springframework.amqp:spring-rabbit:1.5.5.RELEASE'
      compile("com.h2database:h2")
      compile 'org.quartz-scheduler:quartz:2.2.1'
      compile group: 'joda-time', name: 'joda-time', version: '2.3'
      //compile("com.npspot:jtransit-light:1.0.6")
      compile("io.fastjson:boon:0.33")
      compile fileTree(dir: 'libs', include: '*.jar')
      // end::actuator[]
      testCompile group: 'junit', name: 'junit', version: '4.11'
      testCompile("org.springframework.boot:spring-boot-starter-test")
  }
  
  configurations {
      compile.exclude module: "spring-boot-starter-tomcat"
      compile.exclude module: 'spring-boot-starter-logging'
      runtime.exclude module: "spring-boot-starter-tomcat"
      runtime.exclude module: 'spring-boot-starter-logging'
  }
  
  test {
      reports {
          junitXml.enabled = true
          html.enabled = false
      }
  }
  
  springBoot {
      executable = true
  }
  </code></pre>