如果我在类中使用多级 url,我会收到以下异常@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.
就像根本没有考虑方法级别的映射一样。但是,如果我把即删除部分
也没关系。@RequestMapping("/api")
/v0.1
这是剥离到最小情况的配置:
@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/" />
我正在使用弹簧 3.1。我还尝试将beanalwaysUseFullPath
的属性设置为 true,RequestMappingHandlerMapping
但并没有改变这种情况。