I get the following exception if I use multilevel URLs in a class, for example @RequestMapping("/api/v0.1"):
java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'userController'
bean method getUsers()|to {[/api/v0.1]}: There is already 'userController' bean
method getUser(java.lang.String) mapped.
This is similar to method level comparisons, not taken into account at all.
But this is normal, if I put it @RequestMapping("/api"), that is, I will delete the part /v0.1.
Here is the configuration divided by the minimum case:
@Controller
@RequestMapping("/api/v0.1")
public class UserController {
@RequestMapping(value = "/users")
@ResponseBody
public List<User> getUsers() {
return null;
}
@RequestMapping(value = "/users/{username}")
@ResponseBody
public User getUser(@PathVariable String username) {
return null;
}
}
web.xml
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet-context.xml:
<mvc:annotation-driven />
<mvc:view-controller path="/" view-name="home"/>
<mvc:resources mapping="/assets/**" location="/assets/" />
I am using spring 3.1. I also tried setting the property alwaysUseFullPathto true for the RequestMappingHandlerMappingbean, but that did not change the situation.
source
share