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环境的所有依赖
Spring Boot会将功能场景,都变成一个个的启动器
想要使用什么功能,只需要找到对应的启动器就可以了 start
3、主程序
//@SpringBootApplication 标注这个类是一个Springboot应用
@SpringBootApplication
public class Springboot01HellowordApplication {
public static void main(String[] args) {
//使用反射 让spring应用启动
SpringApplication.run(Springboot01HellowordApplication.class, args);
}
}
注解: Ctrl+鼠标左键点击@SpringBootApplication
@SpringBootConfiguration : Srpingboot的配置
@Configuration : spring的配置类
@Component : 这是一个spring的组件
@EnableAutoConfiguration : 自动配置
@AutoConfigurationPackage : 自动配置包
@Import(AutoConfigurationPackages.Registrar.class) :自动配置“包注册”
@Import(AutoConfigurationImportSelector.class) : 自动配置导入选择
下面是获取所有的配置
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes 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(resource);
上面看不懂的直接看图
点击查看: 思维导图.