Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"NoSuchMethodError getHttpServletMapping" after springboot upgrade

I upgraded from springboot 2.1.3 to 2.2.0. So far things works fine but I noticed when I make a rest request that returns a 400, instead of getting the json response I get the error:

[Tomcat].[localhost]           : Exception Processing ErrorPage[errorCode=0, location=/error]
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;

The funny thing is I get this only when I start the app from Intellij using an emdedded tomcat. (create a mvn profile with "spring-boot:run")

So,

  • With standalone tomcat, it works fine everywhere
  • With embedded tomcat, and only if I start from Intellij I get this error.

But I can do the same thing from command line with

mvn spring-boot:run

which then I have no error ?! As suggested on another post I upgraded my IntelliJ to latest version but didn't help

like image 417
Spring Avatar asked Nov 24 '25 04:11

Spring


2 Answers

I fixed the problem.

Changing property tomcat.version didn't help, so I omitted it and added this to the child pom (trick is it does not work in parent pom). Also note that the version is 2.2.4 and not 2.2.0

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <version>2.2.4.RELEASE</version>
    </dependency>
like image 155
Spring Avatar answered Nov 25 '25 17:11

Spring


i think you have to upgrade the version of ur tomcat emdedded , there is a version mismatch. 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. OR Change tomcat version proprety

<properties> <tomcat.version>8.5.37</tomcat.version> <properties>

NB:The tomcat.version property is a normal Maven property in your pom.xml. Just add the tomcat.version to your existing Maven properties

like image 39
AKDI_Kh Avatar answered Nov 25 '25 16:11

AKDI_Kh