【发布时间】:2014-10-10 23:33:11
【问题描述】:
我正在尝试删除白标错误页面,所以我所做的是为“/error”创建了一个控制器映射,
@RestController
public class IndexController {
@RequestMapping(value = "/error")
public String error() {
return "Error handling";
}
}
但现在我遇到了这个错误。
Exception in thread "AWT-EventQueue-0" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'basicErrorController' bean method
public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletR equest)
to {[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'indexController' bean method
不知道我是否做错了什么。请指教。
编辑:
已添加
error.whitelabel.enabled=false 到 application.properties 文件,仍然出现同样的错误
【问题讨论】:
-
看看这个项目github.com/paulc4/mvc-exceptions/blob/master/src/main/java/…,好像他们有错误页面重新映射。
-
你试过设置
spring.resources.add-mappings=false吗? -
感谢您的建议,是的,仍然出现同样的错误
-
当
/error路径被调用时,你只是想返回一些自定义内容吗?
标签: spring spring-boot