Skip to content

@RequestMapping best match gives wrong Controller method when using wildcards [SPR-5362] #10035

Closed
@spring-projects-issues

Description

@spring-projects-issues

Antony Bowesman opened SPR-5362 and commented

Reference forum message http://forum.springsource.org/showthread.php?t=64011

Given the following two methods in a Controller

@RequestMapping(value="/rest/mail/v1/ipm/*", method=RequestMethod.GET)
public ModelAndView Method1()

@RequestMapping(value="/rest/mail/v1/ipm/*/**", method=RequestMethod.GET)
public ModelAndView Method2()

Given the request path /rest/mail/v1/ipm/JA8AAAAAAAAAKwAB4awBIfRXAeRU it matches the first method, but then chooses the second path as a BETTER match, resulting in the wrong method being called. This is because of the simplistic implementation of isBetterPathMatch() that decides that a longer length path is a better match regardless of the number of elements in the path.

This occurs in AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver.isBetterPathMatch. It clearly does not take account of the extra / in the second path, which is not present in the given URL.

Although it is possible to make a workaround which involves having a single method, where the code then makes decisions based on the request path, it complicates Controller implementations forcing different sets of business logic to be combined.


Affects: 2.5.6

Issue Links:

Referenced from: commits 721f2ca

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions