2

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

Spring
  • 11,333
  • 29
  • 116
  • 185

3 Answers3

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

AKDI_Kh
  • 29
  • 4
  • tomcat.version>8.5.37 gives errors, rightfully because 2.2.0 supports tomcat 9, which I already use – Spring Feb 03 '20 at 14:25
  • Also pls don't steal and copy paste answers from other posts here as if your answer – Spring Feb 03 '20 at 16:06
  • 1
    i tried to help and to learn in same time , this is one of many recharches in google https://stackoverflow.com/questions/54122724/spring-boot-java-lang-nosuchmethoderror-javax-servlet-http-httpservletrequest – AKDI_Kh Feb 04 '20 at 15:06
1

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>
Spring
  • 11,333
  • 29
  • 116
  • 185
0

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.

Benjen
  • 134
  • 1
  • 8