-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Log warning if multiple @PostMapping
, @GetMapping
, etc. annotations are declared
#31962
Comments
@cdmatta Of course you're right from technical point of view. And the way how these things are "implemented" as a composed annotation is extremely elegant. But from a Spring Boot (novice) users view I see these annotations in hundreds of tutorials and articles and if I use them combined they don't cause any problems (compile error, start error, log). One of them just don't work. And even for me (who uses Spring Boot every day for years) it was not clear. And the comment you marked is not very obvious. I read it and did not know that |
@PostMapping
, @GetMapping
, etc not recognized if more than one
@PostMapping
, @GetMapping
, etc not recognized if more than one @PostMapping
, @GetMapping
, etc is honored
That's correct. Spring looks for the first In addition, please note that a locally declared
I don't think that would be a good idea, since each annotation could provide conflicting values for other annotation attributes in The only way to map multiple explicit methods is via
We can definitely mention in the documentation that only a single As for logging a warning, I'm not sure if we want to go that far; however, we'll discuss it within the team. |
@PostMapping
, @GetMapping
, etc is honored@PostMapping
, @GetMapping
, etc. annotations are declared
Team Decision: For Spring Framework For Spring Framework |
@PostMapping
, @GetMapping
, etc. annotations are declared@PostMapping
, @GetMapping
, etc. annotations are declared
…& WebFlux This commit updates the RequestMappingHandlerMapping implementations in Spring MVC and Spring WebFlux so that mixed @RequestMapping and @HttpExchange declarations on the same element are rejected. Note, however, that a @Controller class which implements an interface annotated with @HttpExchange annotations can still inherit the @HttpExchange declarations from the interface or optionally override them locally with @HttpExchange or @RequestMapping annotations. See gh-31962 See gh-32049 Closes gh-32065
If more than one of the
@(Method)Mapping
annotations are used, only one seems to be recognized.Reproduction:
Put
@GetMapping
and@PostMapping
together on a method of a controller:If you now test the endpoint you see that
GET /x
is mapped, butPOST /x
is not (405 - Method Not Allowed).Expectation:
The expectation is that both annotations are processed and both endpoints would be available.
At least there should be a warning that one is ignored.
Tested with:
Spring Boot 3.0.13 on Java 17.0.7
Workaround:
Use
@RequestMapping(method = { ... })
.The text was updated successfully, but these errors were encountered: