当前位置:网站首页>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那一套,这个后面单独的内容来分析。

边栏推荐
- Mise en file d'attente des messages en utilisant jedis Listening redis stream
- Sentimentin tensorflow_ analysis_ cell
- 6.1 - 6.2 Introduction à la cryptographie à clé publique
- LeetCode 19. Delete the penultimate node of the linked list
- 【MYSQL】MySQL 百万级数据量分页查询方法及其优化
- Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
- localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。
- Classic theory: detailed explanation of three handshakes and four waves of TCP protocol
- Fedora alicloud source
- Introduction to alluxio
猜你喜欢

Codeforces Round #800 (Div. 2)

uni-app吸顶固定样式

Recursively traverse directory structure and tree presentation

How to select the data transmission format of instant messaging application

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

The parameter field of the callback address of the payment interface is "notify_url", and an error occurs after encoding and decoding the signed special character URL (,,,,,)

Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing

localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。

Happy New Year!

6.1 - 6.2 公钥密码学简介
随机推荐
Replacing domestic image sources in openwrt for soft routing (take Alibaba cloud as an example)
6.1 - 6.2 公钥密码学简介
data = self._ data_ queue. get(timeout=timeout)
使用Jedis监听Redis Stream 实现消息队列功能
Experience of reading the road to wealth and freedom
Ai+ remote sensing: releasing the value of each pixel
ECCV 2020 double champion team, take you to conquer target detection on the 7th
Tp5.0框架 PDO连接mysql 报错:Too many connections 解决方法
【MYSQL】MySQL 百万级数据量分页查询方法及其优化
cartographer_ local_ trajectory_ builder_ 2d
cartographer_fast_correlative_scan_matcher_2d分支定界粗匹配
Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
【Unity3D】碰撞体组件Collider
How to rewrite a pseudo static URL created by zenpart
慢慢学JVM之缓存行和伪共享
tensorlow:cifar100_ train
cartographer_local_trajectory_builder_2d
PHP 2D / multidimensional arrays are sorted in ascending and descending order according to the specified key values
Why does the mobile IM based on TCP still need to keep the heartbeat alive?
2021年OWASP-TOP10