SpringBoot - 自动装配 源码解析
文章目录
- 源码流程图
- getAutoConfigurationEntry
- 源码图地址
源码流程图
我们找几个比较重要的方法来讲一下
getAutoConfigurationEntry
主要的功能:进行扫描具有META-INF/spring.factories
文件的jar包
/*** Return the {@link AutoConfigurationEntry} based on the {@link AnnotationMetadata}* of the importing {@link Configuration @Configuration} class.* @param annotationMetadata the annotation metadata of the configuration class* @return the auto-configurations that should be imported*/protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {if (!isEnabled(annotationMetadata)) {return EMPTY_ENTRY;}AnnotationAttributes attributes = getAttributes(annotationMetadata);// 从META-INF/spring.factories中获得候选的自动配置类List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);// 排重configurations = removeDuplicates(configurations);//根据EnableAutoConfiguration注解中属性,获取不需要自动装配的类名单Set<String> exclusions = getExclusions(annotationMetadata, attributes);// 根据:@EnableAutoConfiguration.exclude// @EnableAutoConfiguration.excludeName// spring.autoconfigure.exclude 进行排除checkExcludedClasses(configurations, exclusions);// exclusions 也排除configurations.removeAll(exclusions);configurations = getConfigurationClassFilter().filter(configurations);// 这个方法是调用实现了AutoConfigurationImportListener的bean.. 分别把候选的配置名单,和排除的配置名单传进去做扩展fireAutoConfigurationImportEvents(configurations, exclusions);return new AutoConfigurationEntry(configurations, exclusions);}
我们知道任何一个springboot应用,都会引入spring-boot-autoconfigure
,而spring.factories文件就在该包下面。
spring.factories文件是Key=Value形式,多个Value时使用,隔开,该文件中定义了关于初始化,监听器等信息,而真正使自动配置生效的key是org.springframework.boot.autoconfigure.EnableAutoConfiguration
。
@EnableAutoConfiguration
注解通过@SpringBootApplication
被间接的标记在了Spring Boot的启动类上。在SpringApplication.run(…)的内部就会执行selectImports()
方法,找到所有JavaConfig自动配置类的全限定名对应的class,然后将所有自动配置类加载到Spring容器中.
源码图地址
图画好了, 戳这里
SpringBoot - 自动装配 源码解析相关推荐
- SpringBoot自动装配源码解析
Spring Boot 自动装配原理 使用Spring Boot最方便的一点体验在于我们可以几零配置的搭建一个Spring Web项目,那么他是怎么做到不通过配置来对Bean完成注入的呢.这就要归功于 ...
- Springboot自动装配源码分析
Springboot自动装配源码分析 1.从@SpringbootApplication点进去 2.可以看到核心的三个注解 @SpringbootConfiguration @EnableAutoCo ...
- SpringBoot四大核心之自动装配——源码解析
四大核心 1.自动装配:简单配置甚至零配置即可运行项目 2.Actuator:springboot程序监控器 3.starter:jar包的引入,解决jar版本冲突问题 4.CLI:命令行 初学体验 ...
- SpringBoot整合Mybatis源码解析之 @MapperScan
@MapperScan @MapperScan import了一个很重要的MapperScannerRegistrar,一个mapper注册处理器,主要完成 mapper接口的扫描和bean定义的注入 ...
- SpringBoot 自动装配原理解析
自动装配是 Spring Boot 的核心部分,也是 Spring Boot 功能的基础,正是由于自动装配,才 将我们从 Bean 的繁复配置中解脱出来.那么 Spring Boot 中的自动装配指的 ...
- SpringBoot入门-源码解析(雷神)
一.Spring Boot入门 视频学习资料(雷神): https://www.bilibili.com/video/BV19K4y1L7MT?p=1 github: https://github.c ...
- 实例源码_SpringBoot数据库源码解析Template实例化操作
Jdbc TemplateAutoConfiguration 在实践过程中,除了数据源的配置外,我们还会经常用到 Jdbc Template.Jdbc Template是 Spring 对数据库的操作 ...
- 【SpringBoot】Spring手动装配和SpringBoot自动装配
文章目录 1. Warm up 1.1 setter注入 1.2 构造器注入 1.3 属性注入 2. Warm up again 2.1 基于XML的配置 2.2 基于JavaConfig类的配置 3 ...
- SecurityAutoConfiguration源码解析
SecurityAutoConfiguration 详解 SpringBoot 对 Security 的支持类均位于 org.springframework.boot.autoconfigure.se ...
- 8145v5 参数_SpringBoot外化配置源码解析:外化配置简介、参数处理|value|spring|调用|参数值
SpringBoot外化配置源码解析 在前面章节我们讲解了 Spring Boot 的运作核心原理及启动过程中进行的一系列核心操作. 从本章开始,我们将针对在实践过程中应用的不同知识点的源代码进行解读 ...
最新文章
- c++:用顺序表实现简单的栈
- python如何统计出现的次数_Python统计日志中每个IP出现次数的方法
- 程序员必备技能-科学砍需求
- POJ 3253 Fence Repair C++ STL multiset 可解
- AT2161-[ARC065D]シャッフル/Shuffling【dp】
- 某大型银行深化系统技术方案之十六:业务应用层
- SQL Server树型结构数据处理的存储过程
- AV_PIX_FMT_YUV420P12LE’在此作用域中尚未声明
- 【UIKit】UITableView 5
- 办公软件自学教程有哪些
- 初学必看,NFine框架结构加MVC快速开发平台登录流程梳理(附源码)
- matlab实现文本内容批量替换
- 原生JS与其他JS 区别
- csgo/5e机器码解封方法,永久性解除,重装系统都不掉
- Docker文档资料
- lisp弧度转度分秒_度分秒转化成弧度的函数代码
- 源支付3.1版本全开源版+店员监控软件+手机监控APP源码
- 为分布式做准备吧——调用链原理
- 常见的云服务器运营商及相关的优惠活动
- exchange服务器重装后,exchange未正常卸载后 重新安装操作方法.docx
热门文章
- 【大数据】Linkis如何安装部署,及一些常见问题
- android 模拟器后缀名,apk是什么文件?apk文件模拟器是什么?
- 虚拟vpc服务器搭建,服务器搭建vpc
- 输出图形(循环程序,任意字符) 三角形、矩形、平行四边形、菱形
- WPF - Visual调试工具Snoop
- 2008年07月《安全天下事之莫须有的敌人与看得到的威胁》、2008年08月《安全天下事之七月流火》...
- noob学python #1
- 1374:铲雪车(snow)——欧拉回路
- 【Paper笔记】Complement Objective Training
- 移动节点的间接路由方式