'"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



Solution 1:[1]

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

Solution 2:[2]

Just wanted to mention another "solution", because I just faced the same problem, after upgrading to Spring Boot 2.4.0

My App is running on Java 11, Spring Boot 2.4.0 AND JakartaEE Api 8.0.0

For a long time I ignored the Jakarta Version, because I found nothing regarding my problem and this dependency in the web.

But after upgrading JakartaEE to 9.0.0 everything worked out fine.

<dependency>
    <groupId>jakarta.platform</groupId>
    <artifactId>jakarta.jakartaee-api</artifactId>
    <version>9.0.0</version>
</dependency>

That was the solution for my problem :) maybe it helps others.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AKDI_Kh
Solution 2 Benjen