当前位置:网站首页>The Bean's life cycle
The Bean's life cycle
2022-08-01 06:02:00 【Hypnos924】
Bean life cycle
Bean's life cycle is generally divided into 4 stages
Instantation---->Property assignment Populate---->Initialization---->Destruction Destriction
In these 4 stages, it is divided into several small steps, let's go into detail below
First step (instantiating the bean)
There are two cases here. If the BeanFactory container is used, when an uninitialized bean is requested from the container, or an uninitialized dependency needs to be injected into the dependency, the container will call createBean for instantiation
For using the ApplicationContext container, when the container is started, all beans are instantiated by obtaining the information in the BeanDefinition object
Part 2(set to detailed properties)
The instantiated object is encapsulated in the BeanWrapper object, and then Spring will complete the property setting and dependency injection according to the information in the BeanDefinition and the interface for setting properties provided by the BeanWrapper
Step 3 (handling the Aware interface)
Spring will detect whether the object implements the lxxxAware interface. Through the Aware type interface, we can get some resources of the Spring container
This is divided into the following situations
If the bean implements the BeanNameAware interface, the setBeanName(String beanld) method it implements will be called, and the name of the bean is passed in
If the Bean implements the BeanClassLoaderAware interface, call the setBeanCLassLoader() method and pass in the ClassLoader object instance
If the Bean implements the BeanFactoryAware interface, it will be called to implement the setBeanFactory() method, and the Spring factory itself will be passed
If this bean implements the ApplicationContextAware interface, the setApplicationContext(ApplicationContext) method will be called and the Spring context will be passed in
Step 4(BeanPostProcessor preprocessing)
If some custom preprocessing is performed on the bean, then the bean can implement the BeanPostProcessor interface, then the PostProcessorBeaforeInitialization(Object obj,String s) method will be called
Step 5(InitializingBean)
If you implement the InitializingBean interface, you only want the afterPropertiesSet() method
Step 6(init-method)
If the bean is configured with the init-method attribute in the Spring configuration file, its configured initialization method will be called automatically
The seventh step BeanPostProcessor post-processing
After the above steps, the bean has been created correctly, and the bean can be used after that
If the bean implements the BeanPostProccessor interface, the postProccessAfterInitialization(object obj, String s) method will be called; since this method is called at the end of bean initialization, it can be applied to memory or caching techniques
Step 8DisposableBean
When the bean is not needed, it will go through the cleanup phase. If the bean implements the DisposableBean interface, it will call the Destroy() method of other implementations
Step 9destory-method
Finally, if the destruction-method attribute is configured in the Spring configuration of this Bea, its configured destruction method will be called automatically
边栏推荐
- 2022.7.27好题选讲
- 测试工具(四)Jenkins环境搭建与使用
- 滚动条样式修改
- ORACLE modify another user package (package)
- Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
- 【音视频】srs直播平台搭建
- WPF入门项目必知必会-初步了解数据绑定 binding
- ORACLE 实现另外一个用户修改包(package)
- After the image is updated, Glide loading is still the original image problem
- 小白的0基础教程SQL: 安装MYSQL 03
猜你喜欢

dbeaver连接MySQL数据库及错误Connection refusedconnect处理

「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader

WPF入门项目必知必会-初步了解数据绑定 binding

Srping中bean的生命周期

Using FiddlerScript caught poly FiddlerScript 】 【 download

Robot_Framework: commonly used built-in keywords

NDK does not contain any platforms problem solving

中国的机器人增长

Robot_Framework:断言

第5章——以程序方式处理MySQL数据表的数据
随机推荐
datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
测试工具(四)Jenkins环境搭建与使用
flinkcdc对mysql的date字段类型转化有什么解决思路么
matlab 风速模型 小波滤波
About making a progress bar for software initialization for Qt
小白的0基础教程SQL: 关系数据库概述 02
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
基于MATLAB的BP神经网络进行语音特征信号分类
Flip letters using string container
Jupyter shortcuts
More than 2022 cattle guest school game 4 yue
WebSocket实现聊天功能
混合型界面:对话式UI的未来
CSP-S2019 Day1
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
After the image is updated, Glide loading is still the original image problem
第6章——数据库的安全性
【MySQL必知必会】 表的优化 | 充分利用系统资源
Talk about the bugs in using for in to traverse the array in js
vim configuration + ctag is as easy to read code as source insight