SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer

A better servlet 3.0 api dependency entry in pom is available here - https://github.com/SpringSource/greenhouse/tree/servlet3, you should also mark the scope as provided, otherwise the jar will be included in your final war which will interfere with the jar provided by the container which is what seems to be happening in your case.


I had a similar problem without Spring, where mvn tomcat7:run did not work, despite the servlet deploying to OpenShift just fine. As per Biju Kunjummen's answer, the problem for me was which servlet-api I was compiling against.

Broken:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

Fixed:

<dependency>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0.20100224</version>
    <scope>provided</scope>
</dependency>

Not terribly sure why, but it works now.


I was facing the same problem wis gradle tomcat plugin. I updated the tomcat version to 8 and it worked.

plugins {
    id "com.bmuschko.tomcat" version "2.2.2"
    id "java"
    id "eclipse"
    id "idea"
    id "war"
}


dependencies {
    providedCompile ('javax.servlet:javax.servlet-api:3.1.0')
    providedCompile ('javax.servlet.jsp:jsp-api:2.2')
    compile ('org.springframework:spring-webmvc:4.2.1.RELEASE')

    def tomcatVersion = '8.0.27'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"

}