spingboot学习笔记-自动装配原理

原理初探

自动配置:pom.xml

- spring-boot-dependencies:核心依赖在父工程中!
- 我们在写入或者引入一些springboot依赖的时候,不需要指定版本号,就是因为有这些版本仓库

启动器

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>
  • 启动器:就是springboot的启动场景;
  • 比如spring-boot-starter-web,他会帮我们导入web环境所有的依赖!
  • springboot会将所有的功能场景,都变成一个个的启动器;
  • 我们需要使用什么功能,只需要找到对应的启动器就可以了;

主程序

  • @springbootApplication //标注这个类是一个springboot的应用,启动类下所有资源被加载
  • 注解
@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;
   }
  • META-INF/spring.factories:自动配置的核心文件
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值