当前位置:网站首页>Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
2022-07-02 19:31:00 【Light dust ×】
AutowiredAnnotationBeanPostProcessor It's the realization of @Autowired The key to , When was it added to sping In container ?
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
In this, a AnnotationConfigUtils.registerAnnotationConfigProcessors, It's done here AutowiredAnnotationBeanPostProcessor Registration of
To make a long story short , In short , After creating the container ,loadBeanDefinitions Registered at .
Annotation mode
The same whole test method , This time new Yes. AnnotationConfigApplicationContext Not the one above ClassPathXmlApplicationContext
@Test
public void test() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext("com.zubus.bean");
BeforeInstantiation bean = ac.getBean(BeforeInstantiation.class);
bean.doSomeThing();
}
It's a different route , Into the this()
It will new One AnnotatedBeanDefinitionReader
new AnnotatedBeanDefinitionReader() There is a familiar figure in the process of
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
Is it with the above xml The resolved registerComponents It's as like as two peas
you 're right , It's right here
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 ~
边栏推荐
- 搭建哨兵模式reids、redis从节点脱离哨兵集群
- Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
- Preprocessing and preprocessing macros
- 预处理和预处理宏
- xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
- Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
- 【pytorch学习笔记】Tensor
- mysql备份后缀是什么_mysql备份还原
- C file input operation
- ICDE 2023|TKDE Poster Session(CFP)
猜你喜欢
搭建主从模式集群redis
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
PyTorch函数中的__call__和forward函数
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
[paper reading] Ca net: leveraging contextual features for lung cancer prediction
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
Quanzhi A33 uses mainline u-boot
Data dimensionality reduction factor analysis
Yunna | why use the fixed asset management system and how to enable it
随机推荐
Memory management of C
Machine learning notes - time series prediction research: monthly sales of French champagne
Notes de lecture sur le code propre
线程应用实例
Emmet basic syntax
2022 software engineering final exam recall Edition
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Introduction to the paper | application of machine learning in database cardinality estimation
预处理和预处理宏
《重构:改善既有代码的设计》读书笔记(下)
The mybatieshelperpro tool can be generated to the corresponding project folder if necessary
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
codeforces每日5题(均1700)-第四天
Digital scroll strip animation
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
安装单机redis详细教程
横向越权与纵向越权[通俗易懂]
Juypter notebook modify the default open folder and default browser
【pytorch学习笔记】Tensor
PHP asymmetric encryption method private key and public key encryption and decryption method