我无法理解为什么下面给出了一个模糊的映射.
一个.控制器类
@Controller
@RequestMapping("/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String get(Model model) {
return "xx";
}
}
Run Code Online (Sandbox Code Playgroud)
控制台输出:
java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'org.tutorial.spring.controller.EmployeeController#0' bean method
public java.lang.String org.tutorial.spring.controller.EmployeeController.get(org.springframework.ui.Model)
to {[/employees/new],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'employeeController' bean method
public java.lang.String org.tutorial.spring.controller.EmployeeController.get(org.springframework.ui.Model) mapped.
Run Code Online (Sandbox Code Playgroud)
它说方法已被映射.怎么会这样?
湾 web.xml中
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
C.spring.xml
<context:annotation-config />
<context:component-scan base-package="org.tutorial.spring" />
<mvc:annotation-driven />
<bean class="org.tutorial.spring.controller.EmployeeController" />
Run Code Online (Sandbox Code Playgroud)
尝试删除bean元素
<bean class="org.tutorial.spring.controller.EmployeeController" />
Run Code Online (Sandbox Code Playgroud)
来自您的XML.我怀疑这会给你带来麻烦,因为
<context:component-scan base-package="org.tutorial.spring" />
Run Code Online (Sandbox Code Playgroud)
将扫描您的包,并将EmployeeController标识为bean,因为它有注释.然后,您将手动添加相同的bean.
| 归档时间: |
|
| 查看次数: |
9878 次 |
| 最近记录: |