当前位置:网站首页>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 ~
边栏推荐
- Bubble sort array
- [0701] [paper reading] allowing data imbalance issue with perforated input during influence
- Yolov3 trains its own data set to generate train txt
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
- Usage of ieda refactor
- Fastdfs installation
- [paper reading] Ca net: leveraging contextual features for lung cancer prediction
- [error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
- MySQL
- Introduction of Ethernet PHY layer chip lan8720a
猜你喜欢
Processing strategy of message queue message loss and repeated message sending
450-深信服面经1
How performance testing creates business value
Data dimensionality reduction principal component analysis
搭建哨兵模式reids、redis从节点脱离哨兵集群
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
《架构整洁之道》读书笔记(下)
冒泡排序数组
What is 9D movie like? (+ common sense of dimension space)
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
随机推荐
《代码整洁之道》读书笔记
ICDE 2023|TKDE Poster Session(CFP)
Horizontal ultra vires and vertical ultra vires [easy to understand]
《架构整洁之道》读书笔记(下)
Getting started with typescript
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
《重构:改善既有代码的设计》读书笔记(下)
多态的理解以及作用
golang:[]byte转string
股票证券公司排名,有安全保障吗
函数高阶-柯里化实现
2022 software engineering final exam recall Edition
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Processing strategy of message queue message loss and repeated message sending
Virtual machine initialization script, virtual machine mutual secret key free
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
仿京东放大镜效果(pink老师版)
Golang concurrent programming goroutine, channel, sync
Introduction to the paper | application of machine learning in database cardinality estimation
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下