Skip to content

NoSuchMethodError in UrlPathHelper.skipServletPathDetermination #26112

Closed
@FabioMarangonSMI

Description

@FabioMarangonSMI

Affects: 5.3.1

Launching an application that uses Spring MVC 5.3.1 on a TomCat 8.5 gives the error:

Caused by: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
at org.springframework.web.util.UrlPathHelper.skipServletPathDetermination(UrlPathHelper.java:265) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.web.util.UrlPathHelper.getLookupPathForRequest(UrlPathHelper.java:250) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.web.util.UrlPathHelper.resolveAndCacheLookupPath(UrlPathHelper.java:199) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.handler.AbstractHandlerMapping.initLookupPath(AbstractHandlerMapping.java:567) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal(AbstractUrlHandlerMapping.java:136) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:491) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1255) [spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1037) [spring-webmvc-5.3.1.jar:5.3.1]
... 34 more

The application finds servlet-api version 4.0.1 in it's classpath (so isServlet4Present is true), but the HttpServletRequest passed to the method is actually from Tomcat's servlet 3, thus lacking the method getHttpServletMapping.

Activity

self-assigned this
on Nov 18, 2020
added
in: webIssues in web modules (web, webmvc, webflux, websocket)
and removed on Nov 18, 2020
added this to the 5.3.2 milestone on Nov 18, 2020
jhoeller

jhoeller commented on Nov 18, 2020

@jhoeller
Contributor

I'll refine that check for 5.3.2: towards presence of the HttpServletRequest.getHttpServletMapping method rather than the HttpServletMapping type. However, please also double-check the presence of Servlet API jars in your classpath; you shouldn't have that Servlet API 4.0.1 jar around in the first place when running on Tomcat 8.5.

quaff

quaff commented on Nov 19, 2020

@quaff
Contributor

Nice work, I have similar issue, I'm targeting servlet 4.0(Tomcat9) but I also provide embedded runtime using Jetty 9.4 which contains servlet 3.1 api, some tests is broken when I upgrade to spring 5.3.0.

jhoeller

jhoeller commented on Nov 19, 2020

@jhoeller
Contributor

@FabioMarangonSMI @quaff it'd be great to verify that the latest 5.3.2 snapshot (https://repo.spring.io/snapshot/org/springframework/spring-framework-bom/) works for your scenarios. This is now as specific and as defensive as possible, so beyond this fix, the only thing to do about mismatches in the classpath is to enforce the presence of a single Servlet API jar.

quaff

quaff commented on Nov 19, 2020

@quaff
Contributor

@jhoeller works fine for me now, thanks.

FabioMarangonSMI

FabioMarangonSMI commented on Nov 19, 2020

@FabioMarangonSMI
Author

@jhoeller yeah, working here too, good job 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @quaff@jhoeller@spring-projects-issues@FabioMarangonSMI

      Issue actions

        NoSuchMethodError in UrlPathHelper.skipServletPathDetermination · Issue #26112 · spring-projects/spring-framework