项目结构
- spring-boot:基础工程,webServer、applicatonContext、environemt、dataSource等基础实现
- spring-autuator:应用程序监控模块,提供存储层、认证层常见组件的指标观测
- spring-boot-autoconfigure: 依赖spring-boot, 自动装配的核心,引入了存储层(h2, redis, mysql, jooq, redis, elasticsearch的依赖,实现自动装配)。
- spring-boot-dependencies: 定义了依赖项的版本号,只有一个build.gradle文件
- spring-boot-parent: 依赖了spring-boot-dependencies, 同时依赖一些构建插件,只有一个build.gradle文件。
- spring-boot-starters:启动器,封装存储层(redis、MongoDB、es、rest等)的实现,以及web层等。
- spring-boot-test: 单元测试
- spring-boot-tools: 包括maven、gradle项目构建插件、cli工具、 jar包加载相关的工具
核心工程是:spring-boot、spring-boot-autoconfigure、spring-boot-starters。
springboot的核心模块是spring-boot 和 spring-boot-autoconfigure.
spring-boot-starter只是在前两个模块的基础上增加了spring相关的依赖项, 只有一个build.gradle文件。
spring-boot模块
类图如下:
核心接口:
WebServerFactory:
WebServerApplicationContext:
ReactiveWebApplicatioinContext:
ServerContextInitializer
SpringApplicationEvent
PlaceHolderResolver
spring-boot-autoconfigure
核心:自动装配。
主要作用是将组件相关的配置自动注入到bean容器,例如:当引入spring-kafka依赖时,由于@ConditionalOnClass(KafkaTemplate.class)注解以及@ConditionalOnMissBean(KafkaTemplate.class)注解,将会自动注入KafakTemplate实例到bean容器中。
该模块包含了自动注入相关的注解,如@AutoConfiguration, @SpringBootApplication, 条件注入相关的注解如:@ConditionalOnClass @ConditionalOnMissBean 以及bean选择器AutoConfigurationImportSelector。
除了自动注入相关的注解之外, 内部包含了常用的组件:包括es、redis、jooq、jdbc、kafak、amqp、web等。
由于spring-boot-starter都引入了该模块,所以当引入spring-boot-starter-data-redis时,可以自动注入RedisTemplate实例。
目录如下:
AbstractDependsOnBeanFactoryPostProcessor.java
AutoConfiguration.java
AutoConfigurationExcludeFilter.java
AutoConfigurationImportEvent.java
AutoConfigurationImportFilter.java
AutoConfigurationImportListener.java
AutoConfigurationImportSelector.java
AutoConfigurationMetadata.java
AutoConfigurationMetadataLoader.java
AutoConfigurationPackage.java
AutoConfigurationPackages.java
AutoConfigurationSorter.java
AutoConfigurations.java
AutoConfigureAfter.java
AutoConfigureBefore.java
AutoConfigureOrder.java
BackgroundPreinitializer.java
EnableAutoConfiguration.java
ImportAutoConfiguration.java
ImportAutoConfigurationImportSelector.java
SharedMetadataReaderFactoryContextInitializer.java
SpringBootApplication.java
admin
amqp
aop
availability
batch
cache
cassandra
codec
condition
context
couchbase
dao
data
diagnostics
domain
elasticsearch
flyway
freemarker
graphql
groovy
gson
h2
hateoas
hazelcast
http
influx
info
integration
jackson
jdbc
jersey
jms
jmx
jooq
jsonb
kafka
ldap
liquibase
logging
mail
quartz
r2dbc
reactor
rsocket
security
sendgrid
service
session
sql
ssl
task
template
thread
thymeleaf
transaction
validation
web
webservices
websocket
Sping-boot-starter:
模块如下, 以下模块源码中都只有一个build.gradle,本质上就是依赖组合:
spring-boot-starter:依赖spring-boot模块、spring-boot-autoconfigure模块、spring-boot-starter-logging模块、spring-core模块
以下模块均依赖spring-boot-starter模块,除此之外引入了组件对应的SDK或client包。
spring-boot-starter-activemq:
spring-boot-starter-actuator
spring-boot-starter-amqp
spring-boot-starter-aop
spring-boot-starter-artemis
spring-boot-starter-batch
spring-boot-starter-cache
spring-boot-starter-data-cassandra
spring-boot-starter-data-cassandra-reactive
spring-boot-starter-data-couchbase
spring-boot-starter-data-couchbase-reactive
spring-boot-starter-data-elasticsearch
spring-boot-starter-data-jdbc
spring-boot-starter-data-jpa
spring-boot-starter-data-ldap
spring-boot-starter-data-mongodb
spring-boot-starter-data-mongodb-reactive
spring-boot-starter-data-neo4j
spring-boot-starter-data-r2dbc
spring-boot-starter-data-redis
spring-boot-starter-data-redis-reactive
spring-boot-starter-test
spring-boot-starter-thymeleaf
spring-boot-starter-tomcat
spring-boot-starter-undertow
spring-boot-starter-validation
spring-boot-starter-web
spring-boot-starter-web-services
spring-boot-starter-webflux
spring-boot-starter-websocket
后续会提供spring-boot模块的核心源码解析。