I'd like to version my REST-Webservice by providing different Accept header values for different versions (see http://barelyenough.org/blog/2008/05/versioning-rest-web-services/).
The problem is, it does not seem to be possible with Spring MVC 3.
My controller looks like this:
@Controller
@RequestMapping("test")
public class RestController {
@RequestMapping(method = RequestMethod.GET, produces = "application/vnd.example.item-v1+json")
@ResponseBody
public ItemV1 getItem() {
return new ItemV1();
}
@RequestMapping(method = RequestMethod.GET, produces = "application/vnd.example.item-v2+json")
@ResponseBody
public ItemV2 getItem2() {
return new ItemV2();
}
}
When I try to access one of these methods, I get an Exception:
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/test'
Am I missing something, or ist this impossible with Spring MVC? I know that it is possible with JAX-RS...
produces
values against theMediaType
class? Maybe you need to extend that class and add your custom values to that? - nickdos