bcosynot
bcosynot

Reputation: 6013

org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer

This error comes up while trying to run tomcatRun task via gradle Apparently this is caused due to dependency issues. My build.gradle file is pasted below:

    apply plugin: 'war'
apply plugin: 'tomcat'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

//these create the 'provided' scope, mainly for the servlet dependency
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'

buildscript {
  repositories {
    mavenCentral()
    maven {
      url "http://download.java.net/maven/2"
    }
    maven { url 'http://repo.spring.io/plugins-release' }
    maven { url 'http://repo.spring.io/milestone/'}
  }

  dependencies {
    classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8'
    classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.1'
  }
}

repositories {
    mavenCentral()
    maven { url 'http://repo.spring.io/milestone/'}
}

dependencies {

    def tomcatVersion = '7.0.42'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
      exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }

    compile 'org.springframework:spring-core:4.0.2.RELEASE'
    compile 'org.springframework:spring-webmvc:4.0.2.RELEASE'

    compile 'org.springframework.data:spring-data-jpa:1.5.1.RELEASE'
    compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
    compile 'org.hibernate:hibernate-entitymanager:4.3.4.Final'

    compile 'postgresql:postgresql:9.1-901.jdbc4'

    provided 'javax.servlet:javax.servlet-api:3.0.1'

    runtime 'com.fasterxml.jackson.core:jackson-core:2.2.2'
    runtime 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
    runtime 'javax.xml.bind:jaxb-api:2.2.9'

    compile 'org.slf4j:slf4j-api:1.7.5'
    runtime 'org.slf4j:slf4j-jdk14:1.7.5'

    testCompile 'com.jayway.jsonpath:json-path:0.8.1'
    testCompile 'com.jayway.jsonpath:json-path-assert:0.8.1'
    testCompile 'org.springframework:spring-test:3.2.8.RELEASE'
    testCompile 'junit:junit:4.+'
    testCompile "org.mockito:mockito-all:1.9.5"
}

// tag::wrapper[]
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
// end::wrapper[]


tomcatRunWar.contextPath = ''

How can this error be resolved?

Upvotes: 0

Views: 4747

Answers (1)

andih
andih

Reputation: 5603

spring-data-jpa 1.5.1 depends on servlet-api 2.5

So at least there exists some conflict. Check the dependency tree of your project for possible conflicts especially check whether the spring framework and servlet api dependencies.

Upvotes: 1

Related Questions