文章目录
spring-boot依赖
spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
此依赖用于管理项目资源过滤以及项目中的所有插件(这一步很明显是把web完全组织为一个application)
配置资源过滤以及插件管理
<build>
<!--配置文件资源.ymal .yml .properties-->
<resources>
</resources>
<!--插件-->
<pluginManagement>
</pluginManagement>
</build>
spring-boot-dependencies
spring-boot-dependencies是spring-boot-starter-parent 的父依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
存放该springboot项目中所有依赖以及依赖的版本
<!--版本号-->
<properties>
</properties>
<!--项目依赖-->
<dependencyManagement>
<dependencies>
<dependency>
<version>${activemq.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
spring-boot应用主程序类
@SpringBootApplication
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
@SpringbootApplication注解分解
@SpringbootApplication SpringBoot应用
@ComponentScan 自动扫描注册bean
@SpringBootConfiguration SpringBoot配置类
@Configuration Spring配置类
@Component Spring组件(该启动类是Spring中的一个组件,负责启动应用)
@EnableAutoConfiguration 自动配置功能
@AutoConfigurationPackage 自动配置包
@Import({Registrar.class}) 将主启动类的所在包及子包中的组件扫描到Spring容器
@Import({AutoConfigurationImportSelector.class}) 导入自动配置导入选择器
AutoConfigurationImportSelector
查询到Springboot的预设的自动配置类
//获得预设配置
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
return configurations;
}
spring.factories
存在于spring-boot-autoconfigure包中
spring.factories中存放着所有springboot自动使用JavaConfig类方式实现的spring组件,比如数据源、缓存机制、数据库驱动等,点进去可以看到具体的配置情况。