SpringBoot
2021/9/9 6:06:00
本文主要是介绍SpringBoot,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录- SpringBoot
- 原理初探
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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-04TiDB 资源管控的对撞测试以及最佳实践架构
- 2024-07-03万字长文聊聊Web3的组成架构
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现