1. Automatic configuration of
pom.xml
- spring-boot-dependencies: The core is in the parent project
- When we write or introduce some Springboot dependencies, we don't need to specify the version because there are these version repositories.
2. Launcher
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
- Starter: To put it bluntly, it is the startup scene of springboot
- For example, spring-boot-starter-web will help us automatically import all the dependencies of the web environment
- springboot will turn all the functional scenarios into one starter
- What function we want to use, we only need to find the corresponding launcher
3. The main program
//@SpringBootApplication 标注这个类是一个springboot的应用
@SpringBootApplication
public class BlogApplication {
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
}
}
- annotation
@SpringBootConfiguration : springboot的配置
@Configuration
@Component : 说明也是一个spring的组件
@EnableAutoConfiguration : 自动配置
@AutoConfigurationPackage : 自动配置包
@Import(AutoConfigurationPackages.Registrar.class) : 自动配置包注册
@Import(EnableAutoConfigurationImportSelector.class) : 自动配置导入选择
//获取所有的配置
List<String> configurations = getCandidateConfigurations(annotationMetadata,
attributes);
Get candidate configurations
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));