László Stahorszki opened SPR-17119 and commented
When using the @GetMapping, @PostMapping, ... shorthand annotations, except for the first one, all these annotation are ignored.
Of course it means that only the first @RequestMapping annotation is being used.
After short looking around, I'd guess instead of using the
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
in org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:257, maybe using
Set<RequestMapping> requestMapping = AnnotatedElementUtils.findAllMergedAnnotations(element, RequestMapping.class);
plus required refactors with it could improve the situation.
Thanks in advance,
László Stahorszki
Affects: 5.1 RC1
Comment From: rstoyanchev
I don't understand the use case. A GET usually returns information, while a POST consumes data, so they don't mix well on the same method, both in terms of attributes (one may use consumes, the other may use params, etc) and method signatures.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: micvm
Hi, sorry for jumping in here but I think I have the same issue (running Spring 4.3.22.RELEASE).
You may want to bind Controller methods e.g. to multiple POST requests depending on the parameters provided. For instance, I have the following Controller specified (simplified):
@PostMapping(params = "type=unsubscribe")
public @ResponseBody String unsubscribe(WebRequest request) {
...
}
@GetMapping
public ModelAndView handleRequestInternal(final HttpServletRequest request,
final HttpServletResponse response) {
...
}
@PostMapping(params = "type=subscribe")
public @ResponseBody String subscribe(WebRequest request) {
...
}
When a POST is sent, the first PostMapping fires all the time, regardless of the parameter value (in the above case, "type" is ignored and "unsubscribe" fires for every POST request) specified. Unfortunately I can not change the requests coming which are provided by a third party. I think this might be related to the above-mentioned issue.
Comment From: bclozel
@micvm This looks like another issue altogether. The current issue is about mixing several Mapping annotations on the same controller method, which you're not doing.
Moreover, I've tried to reproduce this with Spring Boot 1.5.19.RELEASE and couldn't. If you can reproduce that with a repro project, could you create another issue and point to a simple project reproducing the problem?
Thanks,
Comment From: micvm
Thanks. I will try and open a new issue in case.