当前位置:网站首页>Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
2022-07-02 19:31:00 【Light dust ×】
Annotation mode
Write a test method ,new Yes. AnnotationConfigApplicationContext , Appoint basePackages
@Test
public void test() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext("com.zubus.bean");
BeforeInstantiation bean = ac.getBean(BeforeInstantiation.class);
bean.doSomeThing();
}Into the this()

It will new One AnnotatedBeanDefinitionReader


new AnnotatedBeanDefinitionReader() In the process of , There is a different line of code
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
Continue to follow up

It is in this method , hold AutowiredAnnotationBeanPostProcessor Your registration is Set<BeanDefinitionHolder> in

xml The way
In the use of xml In the process of mode development , Our program entry is generally ClassPathXmlApplicationContext
@Test
public void test() throws Exception{
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-test.xml");
Student student = (Student)applicationContext.getBean("student");
System.out.println(student.getUsername()+" "+student.getPassword());
}establish ClassPathXmlApplicationContext when , Would call this Constructors

Call the parent constructor in the constructor , Finish loading some properties , And the resolution of the configuration file path , Then get to the point ——refresh()

At the core refresh() In the method , One step is to create BeanFactory

establish BeanFactory after , It incidentally brings our xml The configuration file is also parsed

establish BeanFactory, then loadBeanDefinitions
loadBeanDefinitions The process is complicated , Those who are interested can go line by line degbug Source code , Here are a few key steps

Several of the same name loadBeanDefinitions Tune in and out , It's best to transfer to a real worker doLoadBeanDefinitions

loadBeanDefinitions Not the focus of attention this time ,doLoadBeanDefinitions There is no need to delve into the details of , What's important is that doLoadBeanDefinitions After completion , I just got one Document Get object , It's not what we want bean Defining information , namely BeanDefinition, So we went on a call registerBeanDefinitions Steps for

In this registerBeanDefinitions In the process of , Nine twists and eighteen turns

Also tone do The first method is to do real work 
Start parsing the previous Document 了

There are two types of parsed tags , One is DefaultElement, One is CustomElement

A digression , What is? DefaultElement, These four are , Namely import、alias、bean、beans, let me put it another way , Except for these four , Everything else is CustomElement

In my test environment , The first label is context, Nature is walking parseCustomElement

Then continue to analyze

Transfer to NamespaceHandlerSupport Of parse Method

Further down is ComponentScanBeanDefinitionParser Of parse Method , It's finally over , The tag is parsed and encapsulated into BeanDefinitionHolder, Then there is another action registerComponents

It's this humble little action ,registerComponents, It contains mystery

This one in here AnnotationConfigUtils.registerAnnotationConfigProcessors, Are you familiar with it? Yes , I'm here again , That's it AutowiredAnnotationBeanPostProcessor Registration of
It's much more complicated than annotation , It's too deep , To make a long story short , In short ,xml The way is to create the container ,loadBeanDefinitions Registered at .
thus , Under two development modes AutowiredAnnotationBeanPostProcessor We have mastered the registration time
This is just registration , The next step is to analyze where it was not created as an object
The next step is to analyze where it is called and executed
Please look at the next breakdown ~
边栏推荐
- SIFT特征点提取「建议收藏」
- PHP asymmetric encryption method private key and public key encryption and decryption method
- 【pytorch学习笔记】Tensor
- Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
- MySQL advanced (Advanced) SQL statement
- Golang并发编程——goroutine、channel、sync
- How to print mybats log plug-in using XML file
- SIFT feature point extraction "suggestions collection"
- 思考变量引起的巨大变化
- Bubble sort array
猜你喜欢

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

安装单机redis详细教程

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统

IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config

Use cheat engine to modify money, life and stars in Kingdom rush
![[paper reading] Ca net: leveraging contextual features for lung cancer prediction](/img/ef/bb48ee88d5dc6fe876a498ab53106e.png)
[paper reading] Ca net: leveraging contextual features for lung cancer prediction

End to end object detection with transformers (Detr) paper reading and understanding

Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management

Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others

数据降维——主成分分析
随机推荐
Golang:[]byte to string
Data dimensionality reduction factor analysis
What is 9D movie like? (+ common sense of dimension space)
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
MySQL
MySQL高级(进阶)SQL语句
Date tool class (updated from time to time)
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
mysql备份后缀是什么_mysql备份还原
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
2022.7.1-----leetcode. two hundred and forty-one
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
《重构:改善既有代码的设计》读书笔记(下)
Golang concurrent programming goroutine, channel, sync
安装单机redis详细教程
搭建哨兵模式reids、redis从节点脱离哨兵集群
二进制操作
ORA-01455: converting column overflows integer datatype
【pytorch学习笔记】Tensor
Yunna | why use the fixed asset management system and how to enable it
