1.自动配置
pom.xml
- spring-boot-dependencies: 核心在父工程中
- 我们在写或者引入一些Springboot依赖的时候,不需要指定版本,就是因为有这些版本仓库
2.启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
- 启动器: 说白了就是springboot的启动场景
- 比如spring-boot-starter-web,就会帮我们自动导入web环境的所有依赖
- springboot会将所有的功能场景,都变成一个个的启动器
- 我们要使用什么功能,就只需要找到对应的启动器就行了
3.主程序
//@SpringBootApplication 标注这个类是一个springboot的应用
@SpringBootApplication
public class BlogApplication {
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
}
}
- 注解
@SpringBootConfiguration : springboot的配置
@Configuration
@Component : 说明也是一个spring的组件
@EnableAutoConfiguration : 自动配置
@AutoConfigurationPackage : 自动配置包
@Import(AutoConfigurationPackages.Registrar.class) : 自动配置包注册
@Import(EnableAutoConfigurationImportSelector.class) : 自动配置导入选择
//获取所有的配置
List<String> configurations = getCandidateConfigurations(annotationMetadata,
attributes);
获取候选的配置
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
AnnotationAttributes attributes) {
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(
getSpringFactoriesLoaderFactoryClass(), 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;
}
META-INF/spring.factories
//所有的类加载到配置类中
Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));