当前位置:网站首页>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 ~
边栏推荐
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
- MySQL表历史数据清理总结
- C file input operation
- "Patient's family, please come here" reading notes
- 移动机器人路径规划:人工势场法[通俗易懂]
- 守望先锋世界观架构 ——(一款好的游戏是怎么来的)
- Qpropertyanimation use and toast case list in QT
- Emmet basic syntax
- Horizontal ultra vires and vertical ultra vires [easy to understand]
- 《代码整洁之道》读书笔记
猜你喜欢
安装单机redis详细教程
《重构:改善既有代码的设计》读书笔记(下)
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
机器学习笔记 - 时间序列预测研究:法国香槟的月销量
Talk about the design of red envelope activities in e-commerce system
程序猿入门攻略(十二)——数据的存储
IEDA refactor的用法
ICDE 2023|TKDE Poster Session(CFP)
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
Advanced performance test series "24. Execute SQL script through JDBC"
C file input operation
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
2022.7.1-----leetcode. two hundred and forty-one
全志A33使用主线U-Boot
Usage of ieda refactor
How performance testing creates business value
PHP parser badminton reservation applet development requires online system
How to print mybats log plug-in using XML file
A4988 drive stepper motor "recommended collection"
预处理和预处理宏
【测试开发】一文带你了解什么是软件测试
Codeworks 5 questions per day (1700 average) - day 4
juypter notebook 修改默认打开文件夹以及默认浏览器
Microservice technology - distributed global ID in high concurrency
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
Markdown基础语法