SpringBoot里实现了某个接口的实现类运行时如何注入的?
待注入的代码位置:
elementType:
when is this hook injected?
Candidates是在这个方法里解析出来的:protected Map<String, Object> findAutowireCandidates
protected Map<String, Object> findAutowireCandidates(@Nullable String beanName, Class<?> requiredType, DependencyDescriptor descriptor) {String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, requiredType, true, descriptor.isEager());Map<String, Object> result = new LinkedHashMap<>(candidateNames.length);for (Map.Entry<Class<?>, Object> classObjectEntry : this.resolvableDependencies.entrySet()) {Class<?> autowiringType = classObjectEntry.getKey();if (autowiringType.isAssignableFrom(requiredType)) {Object autowiringValue = classObjectEntry.getValue();autowiringValue = AutowireUtils.resolveAutowiringValue(autowiringValue, requiredType);if (requiredType.isInstance(autowiringValue)) {result.put(ObjectUtils.identityToString(autowiringValue), autowiringValue);break;}}}for (String candidate : candidateNames) {if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) {addCandidateEntry(result, candidate, descriptor, requiredType);}}if (result.isEmpty()) {boolean multiple = indicatesMultipleBeans(requiredType);// Consider fallback matches if the first pass failed to find anything...DependencyDescriptor fallbackDescriptor = descriptor.forFallbackMatch();for (String candidate : candidateNames) {if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, fallbackDescriptor) &&(!multiple || getAutowireCandidateResolver().hasQualifier(descriptor))) {addCandidateEntry(result, candidate, descriptor, requiredType);}}if (result.isEmpty() && !multiple) {// Consider self references as a final pass...// but in the case of a dependency collection, not the very same bean itself.for (String candidate : candidateNames) {if (isSelfReference(beanName, candidate) &&(!(descriptor instanceof MultiElementDescriptor) || !beanName.equals(candidate)) &&isAutowireCandidate(candidate, fallbackDescriptor)) {addCandidateEntry(result, candidate, descriptor, requiredType);}}}}return result;}
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
SpringBoot里实现了某个接口的实现类运行时如何注入的?相关推荐
- 什么是Kubernetes的CRI - 容器运行时接口
我们都知道Kubernetes不会直接和容器打交道,Kubernetes的使用者能接触到的概念只有pod,而pod里包含了多个容器.当我们在Kubernetes里用kubectl执行各种命令时,Kub ...
- SAP UI5 进阶 - XML 视图里定义的 UI 控件,运行时实例化的技术细节剖析试读版
一套适合 SAP UI5 初学者循序渐进的学习教程 作者简介 Jerry Wang,2007 年从电子科技大学计算机专业硕士毕业后加入 SAP 成都研究院工作至今.Jerry 是 SAP 社区导师,S ...
- springboot幂等性_如何使用 SpringBoot + Redis 优雅的解决接口幂等性问题
前言: 在实际的开发项目中,一个对外暴露的接口往往会面临,瞬间大量的重复的请求提交,如果想过滤掉重复请求造成对业务的伤害,那就需要实现幂等! 我们来解释一下幂等的概念: 任意多次执行所产生的影响均与一 ...
- redistemplate使用_如何使用 SpringBoot + Redis 优雅的解决接口幂等性问题
# 前言 在实际的开发项目中,一个对外暴露的接口往往会面临很多次请求,我们来解释一下幂等的概念:任意多次执行所产生的影响均与一次执行的影响相同.按照这个含义,最终的含义就是 对数据库的影响只能是一次性 ...
- springboot+cxf框架开发SOAP接口
什么是SOAP SOAP是 simple object access protocol(简单对象访问协议)的缩写.这个协议是用http的post请求实现的,跟一般的post请求不同的是,在请求的hea ...
- IDEA中进行SpringBoot整合spring-ws开发webservice接口后期要修改xsd文件流程
场景 SpringBoot整合spring-ws开发webservice接口(全流程详细教程) 参照: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/articl ...
- vue打包放到Java项目里_如何把vuejs打包出来的文件整合到springboot里
这个需求不知道是不是合适,因为静态的vuejs项目,用nginx部署,听说很快. 一般有这个需求的,都是用tomcat来部署java项目,tomcat转发静态vuejs,应该不会很快. 好吧,以上都是 ...
- 05使用jmeter里调试一个下单接口
1. 用charles抓包,下单并收银的包: https://microtestcalm.******.com/*****/v1/trade/create+cash 将请求数据复制下来: { &quo ...
- Springboot使用FastJson后,接口返回中文乱码的问题解决。
Springboot使用FastJson后,接口返回中文乱码的问题解决. 参考文章: (1)Springboot使用FastJson后,接口返回中文乱码的问题解决. (2)https://www.cn ...
最新文章
- 【深度学习】网络架构设计:CNN based和Transformer based
- 自然语言处理之AI深度学习顶级实战
- 安装memcached服务和PECL关于memcache的两个PHP扩展
- Linux系统时间与RTC时间【转】
- 关于 angularjs 的小结
- web.config中配置字符串中特殊字符的处理
- 从UnitedStack OS 1.0 Preview试用申请问卷调查学习OpenStack
- 【opencv】【mediapipe】手势检测的有趣玩法
- 模板方法设计模式(未完待续)
- Android 系统(48)---WindowManager.LayoutParams 详解
- java一次性查询几十万,几百万数据解决办法
- tensorflow 的版本差异与变化
- mac下cocos2dx(带jsoncpp第三方库)编译为android项目心得
- java订餐系统简单版
- 使用FFmpeg工具进行推流、拉流、截图、变速、转换,及常见问题处理
- ​Flink 流处理在中信建投证券的实践与应用
- 方差,标准差,协方差,样本标准差,总体标准差,抽样平均误差
- PISCES P4-vSwitch 安装以及一次失败的测试
- Android 蓝牙强度Rssi
- 10步搞定App内测发布(蒲公英内测平台)