Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path variable in class-level @RequestMapping not working properly [SPR-8858] #13500

Closed
spring-projects-issues opened this issue Nov 18, 2011 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 18, 2011

Bozhidar Bozhanov opened SPR-8858 and commented

@RequestMapping("/{foo}")
public class FooController {
   @RequestMapping("/bar")
   public String bar(@PathVariable String foo) {
   }
}

That is not parsed properly - the path spring maps it to is simply "/bar". To make it work, you have a number of options:

  • /{foo}/ (add a slash)
  • /{foo}/baz (add anything after that)
  • /bar/ (add a trailing slash)

That way it works, but it's not what we want - we want /foo/bar, not /foo//bar, and not /foo/bar/


Affects: 3.1 RC1

Issue Links:

Referenced from: commits b5bcfa0

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

It looks like an unintended consequence of this use case supported in AntPathMatcher's combine() method:

assertEquals("/hotel", pathMatcher.combine("/*", "/hotel"));
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));

We'll investigate a solution. In the mean time you can try using this:

@RequestMapping("/{foo}/")
public class FooController {
   @RequestMapping("bar")
   public String bar(@PathVariable String foo) {
   }
}

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

The combine method of AntPathMatcher now checks if the first pattern contains URI template variable syntax and if so prevents the described behavior from occurring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants