第274天学习打卡(知识点回顾 springboot 定制化原理)

知识点回顾

springboot定制化原理

1.定制化的常见方式

  • 修改配置文件

  • xxxxCustomizer

  • 编写自定义的配置类 xxxConfiguration + @Bean 替换、增加容器中默认组件:视图解析器

  • Web应用编写一个配置类实现WebMvcConfiguration即可定制化web功能, + @Bean给容器中再扩展一些组件

 @Configuration
 public class AdminWebConfi implements WebMvcConfigurer
  • @EnableWebMvc + WebMvcConfigurer----@Bean 可以全面接管SpringMVC,所有规则全部自己重新配置;实现定制和扩展功能

    • 原理

    • 1.WebMvcAutoConfiguration默认的SpringMVC的自动配置功能类。静态资源,欢迎页...

    • 2.一旦使用@EnableWebMvc 会@Import(DelegatingWebMvcConfiguration.class)

    • 3.DelegatingWebMvcConfiguration的作用,只保证SpringMVC最基本的使用

      • 把所有系统中的WebMvcConfigurer拿过来,所有功能的定制都是这些WebMvcConfigurer合起来一起生效

      • 自动配置了一些非常底层的组件。RequestMappingHandlerMapping 这些组件依赖的组件都是从容器中获取

      • public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport

    • 4.WebMvcAutoConfiguration里面的配置要能生效 必须@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)

    • 5.@EnbleWebMvc导致了WebMvcAutoConfiguration没有生效

2.原理分析套路

场景starter -xxxxAutoConfiguration--导入xxx组件-- 绑定xxxProperties----绑定配置文件

雷丰阳2021版SpringBoot2零基础入门springboot全套完整版(spring boot2)哔哩哔哩bilibili

 

 

posted @ 2021-10-09 22:33  豆豆tj  阅读(38)  评论(0编辑  收藏  举报