SpringBoot常用starter解读

 

一,核心starter

1,spring-boot-starter-parent 版本控制

2,spring-boot-starter 核心启动器,依赖为,sprring-boot, spring-boot-autoconfig, spring-boot-starter-logging, spring-core, javax.annotation-api

3,spring-boot-starter-web 支持全栈web开发,依赖为,spring-web, spring-webmvc, spring-boot-starter-tomcat

4,spring-boot-starter-actuator 监控和管理应用

5,spring-boot-starter-test  支持常规测试,依赖为: spring-core, spring-test, junit, spring-boot-test, spring-boot-test-autoconfig

 

二,常用starter

1,spring-boot-starter-jdbc

2,spring-boot-starter-security

3,spring-boot-starter-amqp 

4,spring-boot-starter-data-redis 

5,spring-boot-starter-data-elasticsearch

6,spring-boot-starter-data-mongodb

7,spring-boot-starter-thymeleaf 

8,spring-boot-starter-freemarker

9,spring-boot-starter-mail 

10,spring-boot-starter-aop 

   附:所有starter

 

三,解读 ServletWebServerFactoryAutoConfiguration

Code: 

3.1 先看下标记的注解:

 

@Configuration 配置类注解

@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) 自动配置顺序,最高优先级[同级的还有DispatcherServletAutoConfiguration。扩展下,还有次高级(WebMvcAutoConfiguration),无级别(HttpEncodingAutoConfiguration等),依赖链(属于无级别)]

@ConditionalOnClass(ServletRequest.class) 条件类, 指定的ServletRequest类存在生效

@ConditionalOnWebApplication(type = Type.SERVLET) 条件类,指定为Web应用下生效

@EnableConfigurationProperties(ServerProperties.class) 启动ServerProperties类的属性值注入功能,将server的port, address等属性注入到IOC容器中

@Import({ ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar.class,

 ServletWebServerFactoryConfiguration.EmbeddedTomcat.class,

 ServletWebServerFactoryConfiguration.EmbeddedJetty.class,

 ServletWebServerFactoryConfiguration.EmbeddedUndertow.class }) 导入注册Servlet服务配置类,用于返回指定的容器:Tomcat/Jetty/Undertow

 

 3.2 该自动配置类被执行顺序如下:

1)init: BeanPostProcessorsRegistrar.setBeanFactory/.registerBeanDefinitions

2)return: ServletWebServerFactoryCustomizer

 

3.3  详细Debug看下加载过程为:

a,

b,

c,

 

posted @ 2021-08-08 17:42  牧码良匠  阅读(869)  评论(0编辑  收藏  举报