springmvc遇到的问题

1.打开网页http://localhost:8080/ssm0630springmvc/users2.action 报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'usersController2' method
public java.lang.String com.xyh.controller.UsersController2.test(javax.servlet.http.HttpServletRequest)
to {[/test.action]}: There is already 'com.xyh.controller.UsersController2#0' bean method

如图:
这里写图片描述
经过检查原因是:我写的是注解的controller,但是在springmvc.xml中配置了controller

id="UsersController1" name="/users.action"  class="com.xyh.controller.UsersController1">
   class="com.xyh.controller.UsersController2"/>    

但又同时使用包扫描的方式注入多个处理器

<context:component-scan base-package="com.xyh.controller">context:component-scan>

这就导致了错误提示中说的方法已存在的问题
所以只要将注解的controller部分的bean删掉就可以了

id="UsersController1" name="/users.action"  class="com.xyh.controller.UsersController1">

你可能感兴趣的:(springmvc)