Update 70.2. Customize the ‘whitelabel’ error page.md

master
qibaoguang 2015-04-08 00:11:51 +08:00
parent 7cb9e95048
commit db1e5309f5
1 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1,5 @@
### 70.2. 自定义'白标'whitelabel可以了解下相关理念错误页面
Spring Boot安装了一个'whitelabel'错误页面如果你遇到一个服务器错误机器客户端消费的是JSON其他媒体类型则会看到一个具有正确错误码的合乎情理的响应那就能在客户端浏览器中看到该页面。你可以设置`error.whitelabel.enabled=false`来关闭该功能但通常你想要添加自己的错误页面来取代whitelabel。确切地说如何实现取决于你使用的模板技术。例如你正在使用Thymeleaf你将添加一个error.html模板。如果你正在使用FreeMarker那你将添加一个error.ftl模板。通常你需要的只是一个名称为error的View和/或一个处理`/error`路径的`@Controller`。除非你替换了一些默认配置否则你将在你的ApplicationContext中找到一个BeanNameViewResolver所以一个id为error的`@Bean`可能是完成该操作的一个简单方式。详情参考[ErrorMvcAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java)。
查看[Error Handling](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-error-handling)章节了解下如何将处理器handlers注册到servlet容器中。