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

spring.mvc.servlet.path config cause something strange #25339

Closed
DogeC0in opened this issue Jun 30, 2020 · 5 comments
Closed

spring.mvc.servlet.path config cause something strange #25339

DogeC0in opened this issue Jun 30, 2020 · 5 comments
Labels
status: duplicate A duplicate of another issue

Comments

@DogeC0in
Copy link

DogeC0in commented Jun 30, 2020

Environment:

  • Spring 2.3.0.RELEASE

  • JDK 1.8

Steps to reproduce:

  • Add spring.mvc.servlet.path=/test in application.properties.

  • Define Controller,use @RestController in controller class,
    then use @GetMapping("/test") at one method,
    finally,use @GetMapping("/test1") at other method.

  • start project,visit urls that I want to test.

I expect that:

Actually:

In fact,I find that WebFlux use spring.webflux.base-path=/test has some problems

This is link of My demo: https://github.com/DogeC0in/BugFinder

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 30, 2020
@rstoyanchev
Copy link
Contributor

Please avoid cross-posting:
spring-projects/spring-boot#22158

@rstoyanchev rstoyanchev added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 30, 2020
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 30, 2020

This is a very old part of the code. My best guess is as that this is so for 2 reasons:

  1. For Servlet mappings by extension in which case the pathInfo is null and hence there is no path within the servletPath, i.e. the whole thing is the servletPath.
  2. Even for Servlet mapping by prefix, returning "" isn't a good outcome, because if you have two Servlets mapped to different prefixes (e.g. "/foo" and "/bar"), then requests to "/foo" and to "/bar" would both appear as "" to the application and it would haver no way to differentiate between the two.

My advice is to not use mappings where the servletPath prefix is also duplicated in an application mapping. I would also advise against using a mapping by servletPath prefx, and against relying on the servletPath in any way, in the first place if you can avoid it. It's fraught with bigger issues then just such corner cases.

If you must have a Servlet mapped to "/test" then in your application mappings use "/test1" and "/test2", and if you want also one for "/test" which correspond to URLs "/test/test1", "/test/test2", and "/test" respectively.

@DogeC0in
Copy link
Author

DogeC0in commented Jun 30, 2020

@rstoyanchev
So,only by agreement, It can't be avoided?
Actually,I want http://localhost:8080/test/test work , but http://localhost:8080/test is also available .
And I have a suspicion that WebMvcProperties did not worked.

@DogeC0in DogeC0in changed the title spring.mvc.servlet.path config may cause something wrong spring.mvc.servlet.path config cause something strange Jun 30, 2020
@bclozel
Copy link
Member

bclozel commented Jun 30, 2020

@DogeC0in
We can't change this behavior without breaking legitimate use cases; Rossen pointed out that your setup is flawed in the first place, so this can't be avoided unless you can change this situation with your application. I don't think there's an issue with WebMvcProperties as it's configuring the expected feature in Spring MVC.

@rstoyanchev
Copy link
Contributor

So,only by agreement, It can't be avoided?

Correct, you need to avoid having both the Servlet and an application mapping using the exact same path because they overlap. Make the application mapping different, e.g. "/test1" and "/test2" so you'll have "/test/test1" and "/test/test2" working correctly. Then input path "/test" is for the whole Servlet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants