I am attempting to move a xml-based Spring MVC app to a Java Configuration based app. There appears to be a mismatch with the various java.servlet classes available in mave
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}"
}
I alse get this problem, I use their method to handle it, but failed. my tomcat version i used are 7 and 8.0 , i got get this problem too. when i use tomcat 8.5, there is no problem. my project run successfully.
I used
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
to solve the issue
I am facing the same error when using Tomcat in Eclipse.
I solve this by going to Servers tab > double click the Tomcat and uncheck the "Serve modules without publishing"
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.