org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'basicErrorController' method
public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
to { /error}: There is already 'homeController' bean method
原因:
同一父路径下的方法映射名相同,也就是说RequestMapping里的value值相同。
下面这种情况spring也会报错!
@RequestMapping("/error")
public String error(HttpServletRequest request) {
return "error";
}
@RequestMapping("/error404")
public String error404(HttpServletRequest request) {
return "error-404";
}
视图也会发生这种情况!所以视图不能error-404.jsp、error.jsp这样取名,如果这样取名,spring能找到error-404.jsp视图,但是找不到error.jsp视图。