同springmvc相比,springboot展現出來的核心理念為"約定優于配置"。而實踐這一核心的要素就是各類starter。
spring-boot 核心工程
spring-boot-starters 啟動服務工程
spring-boot-autoconfigure 自動配置的核心工程 負責加載注入spring.factories下的配置starters
spring-boot-actotor 提供應用監控類功能,如endpoints(應用狀态監控), healthindicator(應用健康監控)等
spring-boot-tools 常用工具集,如spring-boot-maven-plugin
spring-boot-cli 指令行互動工具
核心工程為: spring-boot, spring-boot-autoconfigure
一是聲明依賴jar包,二是在依賴jar包中提供autoconfiguration類,實作自動加載屬性。
1,starter
springboot官方推薦使用starter提供一個spring.providers檔案,用來聲明目前starter所依賴的jar包。
例如,spring-boot-starter-web的spring.providers檔案為,
provides: spring-webmvc,spring-web
即,分别提供mvc和web的功能。
2,xxxautoconfiguration的注解解讀
a, conditionalonxxx條件注解
比如conditionalonwebapplication 目前為webapplication才建立bean
conditionalonmissingbean(b.class) 目前指定的b對象不存在才建立。
b,enableconfigurationproperties(xproperties.class) 使用xproperties獲得application.properties的實作
c, import(yconfiguration.class, zconfiguration.class)導入y,z 配置類
d, configuration 基本配置注入屬性。
e,在 resources/meta-inf下建立一個名為spring.factories的檔案,該檔案将告知spring-boot,需要自動配置的屬性類
3, springapplication.run所經過的自動配置屬性注入
1)refreshcontext:refresh:
2)invokebeanfactorypostprocessors:invokebeanfactorypostprocessors
3)invokebeandefinitionregistrypostprocessors:
4)postprocessbeandefinitionregistry:processconfigbeandefinitions
5)parse:processdeferredimportselectors
6)getimports:process:selectimports:
7)getcandidateconfigurations
8)loadfactorynames
code :
configurations:共180個,截取部分
墨匠