Issue Details (XML | Word | Printable)

Key: SPR-5066
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Major Major
Assignee: Arjen Poutsma
Reporter: James Cook
Votes: 1
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Allow multiple RequestMapping annotations

Created: 06/Aug/08 01:12 PM   Updated: 08/Nov/08 04:30 AM   Resolved: 08/Nov/08 04:30 AM
Component/s: SpringWEB
Affects Version/s: 2.5.5
Fix Version/s: 3.0 M1

Time Tracking:
Not Specified


 Description  « Hide

It would be helpful if a method in a controller could be annotated to support more than one request mapping:

@RequestMapping (value = "/company", method = RequestMethod.PUT)
@RequestMapping (value = "/company", method = RequestMethod.POST, params = "method=put")
public String update(Company company) { myService.updateCompany(company); return "redirect:/companies"; }

This will allow a single handler method to respond to a HTML request without support for PUT, and an AJAX call that does support PUT. There are other uses also, but this one is a prime concern for me at the moment.



Arjen Poutsma added a comment - 31/Oct/08 01:08 PM

As Java does not allow multiple annotations of the same type on a method, the only thing we can do is introduce a @RequestMappings annotation that can hold multiple @RequestMapping's, something like:

@RequestMappings{ @RequestMapping (value = "/company", method = RequestMethod.PUT), @RequestMapping (value = "/company", method = RequestMethod.POST, params = "method=put") }
public String update(Company company)


Grant Gochnauer added a comment - 31/Oct/08 01:22 PM

What would be VERY helpful is allow developers to introduce custom @RequestMapping implementations.. This might help in this case.

For example, I might have something like:
@DomainBasedRequestMapping(value = "/home.htm", domain = "mydomain.com")
public String method() {}

@DomainBasedRequestMapping(value = "/home.htm", domain = "myotherdomain.com")
public String method2() {}

I tried doing this in Spring 2.5 but it got VERY difficult.


Arjen Poutsma added a comment - 04/Nov/08 05:05 AM

@Grant: Adding support for custom @RequestMapping annotations is a nice feature to have, but pretty hard to implement. Feel free to create a separate issue for it, though.


Grant Gochnauer added a comment - 04/Nov/08 09:00 AM

Arjen –

Created an improvement request:
http://jira.springframework.org/browse/SPR-5269

Thanks!


Arjen Poutsma added a comment - 08/Nov/08 04:30 AM

After some thought, we will not implement this, because it really complicates the request mapping algorithms. Also, there are alternatives for the underlying cause issue:

  • @RequestMapping already supports multiple paths
  • Support for tunneling PUT and DELETE through POST is already tackled by SPR-5267, specifically, the HiddenHttpMethodFilter.
  • Also, there is always the option of having multiple @RequestMapping methods, one delegating to another.