I have two request mappings in a Spring MVC 3 application, one which takes json and xml, and another that takes application/x-www-form-urlencoded data. Example:
@RequestMapping(value={"/v1/foos"}, method = RequestMethod.POST, consumes={"application/json", "application/xml"})
public FooDTO createFoo(@RequestBody FooDTO requestDTO) throws Exception {
...
}
@RequestMapping(value={"/v1/foos"}, method = RequestMethod.POST, consumes="application/x-www-form-urlencoded")
public FooDTO createFooWithForm(@ModelAttribute FooDTO requestDTO) throws Exception {
...
}
I expected that the different consumes parameter makes each request unique, though I get an java.lang.IllegalStateException: Ambiguous handler methods mapped....
Should consumes and produces makes requests unique? Any ideas?
Edit 1: To add weight to this, if you set the content-type in the header rather than using consumes, this actually works and makes them unique: headers="content-type=application/x-www-form-urlencoded. Perhaps there is a bug with consumes?
Edit 2: We’re using Spring 3.1.1.RELEASE.
This has been resolved by Marten Deinum on the Spring Forum (here):
The solution to this problem was to use the correct HandlerMapping and HandlerAdapter in my servlet configuration:
Thanks Marten.