天天看点

SpringBoot常用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

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

SpringBoot常用starter解读

code: 

SpringBoot常用starter解读

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,

SpringBoot常用starter解读

b,

SpringBoot常用starter解读

c,

SpringBoot常用starter解读

墨匠

继续阅读