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

Handling multiple @XXXMapping annotations on same handler method [SPR-17119] #21656

spring-issuemaster opened this issue Aug 2, 2018 · 5 comments


Copy link

@spring-issuemaster spring-issuemaster commented Aug 2, 2018

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


This comment has been minimized.

Copy link

@rstoyanchev rstoyanchev commented Jan 29, 2019

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.


This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 5, 2019

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.


This comment has been minimized.

Copy link

@micvm micvm commented Feb 7, 2019

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) {

	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.


This comment has been minimized.

Copy link

@bclozel bclozel commented Feb 7, 2019

@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?



This comment has been minimized.

Copy link

@micvm micvm commented Feb 8, 2019

Thanks. I will try and open a new issue in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.