zoukankan
html css js c++ java
SpringBoot高级-自动配置之@EnableAutoConfiguration注解
前言:通过之前的自动配置原理相关介绍的文章,我们对自动配置的流程大概都很清楚了,这里我们对 @EnableAutoConfiguration 注解的实现流程进行跟踪,发掘源码中实现的原理。
一、查看@EnableAutoConfiguration 注解的定义
二、查看@Import导入的ImportSelector接口实现类 AutoConfigurationImportSelector
三、查看实现类 AutoConfigurationImportSelector 的 selectImports() 方法
四、查看 selectImports() 方法,发现其调用了 getAutoConfigurationEntry() 方法
五、查看 getAutoConfigurationEntry() 方法, 发现其调用了 getCandidateConfigurations() 方法
六、查看 getCandidateConfigurations() 方法
断点调试,发现list对象configurations会有117个元素,这些元素就是Bean对象的全限定类名,通过对象的全限定类名将Bean初始化到IOC容器中
在断言中,有一段提示信息"No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct."
找到 spring.factories 文件的位置
打开该文件,注意“”的使用说明。列表中,就有我们熟悉 RestTemplateAutoConfiguration、EmbeddedWebServerFactoryCustomizerAutoConfiguration 等自动配置类
最后,打开一个EmbeddedWebServerFactoryCustomizerAutoConfiguration 看一看
小结:虽然由于@EnableAutoConfiguration 注解的使用,初始化了spring.factories文件列表中的配置类,但是这些配置类中,使用了Condition条件,必须满足Condition条件,才能最终将Bean初始化。
查看全文
相关阅读:
StackStorm简介及其部署
Nginx系列(十二)——性能调整
Nginx系列(十一)——通过日志进行故障排查
Nginx系列(十)——可用性监控进阶
Nginx系列(九)——容器/微服务
Nginx系列(八)——数字媒体流
Nginx系列(七)——HTTP/2
Nginx系列(六)——安全控制
Nginx系列(五)——认证
Nginx系列(四)——配置文件自动化管理
原文地址:https://www.cnblogs.com/elnimo/p/13792568.html
最新文章
【面经】Epic: 数据库去重
2014 Hangjs 见闻流水账第二天
2014 Hangjs 见闻流水账第一天
用node开发repl应用
Hello Kraken.js!
Gradle 构建 android 应用常见问题解决指南
Grunt 新手指南
用node-webkit 开发 PC 客户端
重构博客园Android App
用Pomelo 搭建一个简易的推送平台
热门文章
运维工程师职业技能汇总大全(持续更新)
Centos8和Centos7实际使用区别
MySQL生产环境常见架构
MySQL常见故障汇总
MySQL事务中的redo与undo
腾讯云-TCE容器服务快速上手
Apache httpd server部署
Nginx平滑升级
MySQL5.7配置SSL加密
自动化运维平台Bigops部署
Copyright © 2011-2022 走看看