天天看點

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解讀

墨匠

繼續閱讀