标签:启动器 SpringBoot spring boot springboot starter configurations
目录SpringBoot
原理初探
自动配置:
pom.xml
- spring-boot-starter-parent:核心依赖在父工程中!
- 我们在写或者引入一些Springboot依赖的时候,不需要指定版本,就因为这些版本仓库
启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
- 启动器:说白了就是springboot的启动场景;
- 比如spring-boot-starter-web,他就会帮我们自动导入web环境所有的依赖!
- springboot会将所有的功能场景都变成一个个的启动器
- 如果我们要使用什么功能,就只需要找到对应的启动器就可以了
starter
主程序
//@SpringBootApplication:标注这个类是一个springboot的应用
@SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
//将springboot应用启动
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
-
@SpringBootConfiguration //springboot的配置 @Configuration //spring配置类 @Component //说明这也是一个spring的组件 @EnableAutoConfiguration //自动配置 @AutoConfigurationPackage //自动配置包 @Import({Registrar.class})//自动配置“包注册” @Import({AutoConfigurationImportSelector.class})//自动导入选择 //获取所有的配置 List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);
获取候选的配置
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;
}
标签:启动器,SpringBoot,spring,boot,springboot,starter,configurations 来源: https://www.cnblogs.com/ls-summer/p/15245232.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。