SprinBoot易学难精

Spring Boot易学难精

易学

  • 组件自动装配:规约大于配置,专注核心业务
  • 外部化配置:一次构建、按需调配,到处运行
  • 嵌入式容器:内纸容器、无序部署、独立运行
  • Spring Boot Stater:简化依赖、按需装配、自我包含
  • Production-Ready:一站式运维、生态无缝整合

难精

  • 组件自动装配:模式注解、@Enable模块、条件装配、加载机制
  • 外部化配置:Environment抽象、生命周期、破坏性变更
  • 嵌入式容器:Servlet Web容器、Reactive Web容器
  • Spring Boot Stater:依赖管理、装配条件、装配顺序
  • Production-Ready:健康检查、数据指标、@Endpoint管控

Spring Boot三大特性

  • 组件自动装配:Web MVC、 Web Flux和JDBC
  • 嵌入式Web容器:Tomcat、Jetty和所以及(Undertow)
  • 生产准备特性:指标、健康检查、外部化配置等

核心特性

组件自动装配

  激活:@EnableAutoConfiguration

  配置:/META--INF/spring.factories

  实现:xxxAutoConfiguartion

 在Spring Boot项目中都有如下的启动类:

  

  最重要的就是@SpringBootApplicationSpringApplication.run()其中

  @SpringBootApplication注解部分:

  

   当spring boot扫描到@EnableAutoConfiguration注解时
  则会将spring-boot-autoconfigure.jar/META-INF/spring.factories文件中org.springframework.boot.autoconfigure.EnableAutoConfiguration对应的value里的所有xxxConfiguration类加载到IOC容器中。
  而xxxAutoConfiguration类一般都会有@ConditionalOnxxx注解,通过这些条件注解来判断是否真正的创建xxxConfiguration对象。
  spring boot的各种spring-boot-starter-xxx.jar也正是居于此注解来达到自动装配的目的。


  @EnableAutoConfiguration注解部分:

  

  其中最关键的要属@Import(AutoConfigurationImportSelector.class),借助AutoConfigurationImportSelector,@EnableAutoConfiguration可以帮助SpringBoot应用将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IoC容器。

嵌入式Web容器

  web Servlet:Tomcat、Jetty和Undertow

  web Reactive:Netty Web Server

生产准备特性

  指标:/actuator/metrics

  健康检查:/actuator/health

  外部化配置:/actuator/configprops

posted @ 2019-06-20 15:26  echola_mendes  阅读(238)  评论(0编辑  收藏  举报