当前位置:网站首页>AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
2022-06-26 05:21:00 【轻尘×】
AutowiredAnnotationBeanPostProcessor是spring实现自动装配的基石,根据前文《 internalAutowiredAnnotationProcessor在哪冒出来的?》,我们已经知道了AutowiredAnnotationBeanPostProcessor是什么时候被加入BeanDefinition,那它又是在哪个步骤被实例化的呢?
把断点打在 refresh()方法的invokeBeanFactoryPostProcessors处

我们可以看看invokeBeanFactoryPostProcessor上的注释
/**
* Instantiate and invoke all registered BeanFactoryPostProcessor beans,
* respecting explicit order if given.
* <p>Must be called before singleton instantiation.
*/
用刚过四级的英语水平翻译一下:实例化并调用所有的已注册的BeanFactoryPostProcessor,如果给定了顺序,按顺序来~

那这里会不会实例化AutowiredAnnotationBeanPostProcessor呢?
可以看到,程序运行到时,beaDefinitionNames里面是包含了org.springframework.context.annotation.internalAutowiredAnnotationProcessor的

而存放完成实例化bean的singletonObects里面并没有,也就是说,到目前为止,AutowiredAnnotationBeanPostProcessor还未被实例化

下一步,执行invokeBeanFactoryPostProcessor,再看singletonObects,可以看到,只包含了ConfigurationClassPostProcessor、DefaultEventListenerFactory和EventListenerMethodProcessor的实例化对象

我们关心的AutowiredAnnotationBeanPostProcessor并没有实例化,我想这是因为属于BeanPostProcessor这个体系,而不属于BeanFactoryPostProcessor体系的原因

继续执行registerBeanPostProcessors(beanFactory),执行完可以看到,AutowiredAnnotationBeanPostProcessor已经完成了实例化。

所以可以定位到,AutowiredAnnotationBeanPostProcessor的实例化发生在registerBeanPostProcessors(beanFactory)里面
跟进去看,方法上的注释都看似一样,实际完全不一样,对于invokeBeanFactoryPostProcessor是实例化并执行,而这里是:实例化并注册所有的BeanPostProcessor,也就是说,调用并不发生在这里。
/**
* Instantiate and register all BeanPostProcessor beans,
* respecting explicit order if given.
* <p>Must be called before any instantiation of application beans.
*/
protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) {
PostProcessorRegistrationDelegate.registerBeanPostProcessors(beanFactory, this);
}
为什么呢?
我的理解是BeanFactoryPostProcessor增强的对象是BeanFactory,也就是容器,它们在容器创建过程的前后就需要被执行完,因为后面即将要创建用户定义的对象了,也就是执行finishBeanFactoryInitialization(beanFactory),再拖就来不及了,而BeanPostProcessor增强的对象是bean对象,应该围绕bean的创建前、创建中、创建后来执行,以达到增强bean的效果,故而这里只是实例化和注册,并没有执行。
实例化的过程也和普通bean对象一样,也是getBean/doGetBean/createBean/doCreate/createBeanInstance那一套,这个后面单独的内容来分析。

边栏推荐
- Could not get unknown property ‘*‘ for SigningConfig container of type org.gradle.api.internal
- Beidou navigation technology and industrial application of "chasing dreams in space and feeling for Beidou"
- Red team scoring method statistics
- 《财富自由之路》读书之一点体会
- CMakeLists. txt Template
- 出色的学习能力,才是你唯一可持续的竞争优势
- 【上采样方式-OpenCV插值】
- 关于支付接口回调地址参数字段是“notify_url”,签名过后的特殊字符url编码以后再解码后出现错误(¬ , ¢, ¤, £)
- Briefly describe the pitfalls of mobile IM development: architecture design, communication protocol and client
- 6.1 - 6.2 公钥密码学简介
猜你喜欢

6.1 - 6.2 公鑰密碼學簡介

Windows下安装Tp6.0框架,图文。Thinkphp6.0安装教程

Transport layer TCP protocol and UDP protocol

How does P2P technology reduce the bandwidth of live video by 75%?

【ARM】在NUC977上搭建基于boa的嵌入式web服务器

小小面试题之GET和POST的区别

SOFA Weekly | 开源人—于雨、本周 QA、本周 Contributor

Red team scoring method statistics

【活动推荐】云原生、产业互联网、低代码、Web3、元宇宙……哪个是 2022 年架构热点?...

Anaconda creates tensorflow environment
随机推荐
cartographer_optimization_problem_2d
Serious hazard warning! Log4j execution vulnerability is exposed!
[upsampling method opencv interpolation]
【ARM】在NUC977上搭建基于boa的嵌入式web服务器
How to make your big file upload stable and fast?
Recursively traverse directory structure and tree presentation
【上采样方式-OpenCV插值】
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
第九章 设置结构化日志记录(一)
data = self._ data_ queue. get(timeout=timeout)
LeetCode 19. Delete the penultimate node of the linked list
Protocol selection of mobile IM system: UDP or TCP?
Codeforces Round #800 (Div. 2)
Gd32f3x0 official PWM drive has a small positive bandwidth (inaccurate timing)
创建 SSH 秘钥对 配置步骤
Use jedis to monitor redis stream to realize message queue function
zencart新建的URL怎么重写伪静态
Experience of reading the road to wealth and freedom
[unity3d] rigid body component