Spring MVC 3.1 - REST Web Services Management

I would like to update 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 that this is not possible using Spring MVC 3.

My controller is as follows:

@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 is this not possible with Spring MVC? I know this is possible with JAX-RS ...

+6
source share
1 answer

http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-produces

It should be possible as you have things. How do you specify the Accept header in a GET request? Are you 100% sure that your GET request sends an Accept header value that matches only one or the other of the content types you specify? If you send a header that matches both, then Spring will not know which handler method should process the request.

You may need to enable org.springframework registration in DEBUG to find out what is happening, or use the breakpoint debugger and Spring source code to see what is actually happening. "produces" is a relatively new feature, therefore, an error is also possible.

https://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+SPR+AND+%28summary+%7E+%22mvc+produces%22+OR+description+%7E+%22mvc+produces%22% 29 + AND + status +% 3D + Open

+1
source

Source: https://habr.com/ru/post/910529/


All Articles