I'm getting the following exception if I use multi level urls in class like @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.
It's like the method level mappings doesn't get into consideration at all.
But it's ok if I put @RequestMapping("/api") i.e. remove the /v0.1 part.
Here is the configuration stripped up to the minimal 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:
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="home"/>
<!-- Handles HTTP GET requests for /assets/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<mvc:resources mapping="/assets/**" location="/assets/" />
I'm using spring 3.1. I also tried to set alwaysUseFullPath property to true of the RequestMappingHandlerMapping bean but it didn't change the situation.