学习资料
视频:【尚硅谷】SpringBoot2零基础入门教程
文档:SpringBoot2核心技术与响应式编程
源码:SpringBoot2核心技术与响应式编程
自动配置原理
- 自动配置类:org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
- @Bean 创建DefaultErrorAttributes类型 bean进容器,默认方法名作为bean名 errorAttributes
- 这个类实现了接口:DefaultErrorAttributes implements ErrorAttributes, HandlerExceptionResolver, Ordered
- 这个类中定义了
- @Bean 创建BasicErrorController 类型 bean进容器,默认方法名作为bean名 basicErrorController
- 这个类继承了抽象异常Controller:BasicErrorController extends AbstractErrorController
- 这个类默认处理 /error 路径的请求:@RequestMapping(“${server.error.path:${error.path:/error}}”)
- 这个类有一个方法名为errorHtml返回ModelAndView类型数据,逻辑中返回的视图名是“error”,这个方法就是SpringBoot默认的异常页面,因为此方法的注解:@RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
- 这个类有一个方法名为error返回ResponseEntity
- @Configuration 创建WhitelabelErrorViewConfiguration类型 bean进容器
- @Bean 创建View 类型 bean进容器,名叫 error(上面返回的ModelAndView中的View默认就是这个error)
- @Bean 创建BeanNameViewResolver 类型 bean进容器,它的作用是根据bean名返回视图解析器,我们的视图就是视图解析器给的
- @Configuration 创建DefaultErrorViewResolverConfiguration类型 bean进容器,它的作用是指定错误页面的路径
- @Bean 创建DefaultErrorViewResolver类型 bean进容器,它的作用是指定错误页面的路径