When I run this application on built-in server or other tomcat server it gives me following error message. I am using jdk8, STS V-3.9.7. Can someone help me resolve it
I think there is a version mismatch (possibly a Bug?) in Spring Boot.
Spring Boot 2.1.X uses Tomcat 9 which has the Servlet API v4.
But Spring Boot Web 2.1.X still incorporates Servlet API v3.1.
You should solve the problem by downgrading the spring-boot-starter-tomcat to version 2.0.X.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.0.7.RELEASE</version>
<scope>test</scope>
</dependency>
Edit:
It might as well work just to change the Tomcat version property.
<properties>
<tomcat.version>8.5.37</tomcat.version>
<properties>
merge your DemoAppApplication with servlet initializer as follow:
@SpringBootApplication
public class DemoAppApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(DemoAppApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoAppApplication.class);
}
}
or add @Configuration
annotation to class that extends SpringBootServletInitializer
I had a similar problem and the cause was the jsp-api didn't fit to the corresponding servlet-api version. As Sven Döring already mentioned Spring Boot 2.1.x uses Tomcat 9 which uses/provides Servlet API v4. For this you need jsp-api 2.3.3 otherwise you can get the NoSuchMethodError.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
More info about the version matching can be found here: The ultimate Java version table (J2EE, Java EE, Servlet, JSP, JSTL) Unfortunately Tomcat 9 and Servlet-API 4 is missing in this list.
Below Fix Worked for me. Thanks Sven Döring
<properties>
<tomcat.version>8.5.37</tomcat.version>
<properties>
I'd like to add to answer of Sven Döring solution for gradle:
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springVer) {
exclude module: "spring-boot-starter-tomcat"
}
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: springTomcatVer)
At this point, I set the params:
springVer='2.1.8.RELEASE'
springTomcatVer='2.0.9.RELEASE'