当前位置:网站首页>Bena's life cycle
Bena's life cycle
2022-08-02 23:33:00 【blanceage】
Bean's Lifecycle
- Prepare to create
- Create instantiation
- Dependency Injection
- Container cache
- Destroy the instance
The life cycle of a bean can be divided into five stages, namely preparation before creation, creation and instantiation, dependency injection, container cache, and instance destruction.
Preparation before creation
The main function of this stage is to parse and find Bean-related extension implementations from the context and some configurations before the Bean starts to load.For example, like init-method, a method that the container will call when initializing a bean; destroy-method, a method that the container will call when destroying a bean; and BeanFactoryPostProcessor(), an extension class method provided by spring.Some pre- and post-processing extensions in this type of bean loading process are implemented. These classes or configurations are actually provided by Spring for us to implement some extensions in the bean loading process. In the middle of many integrations with Springitems are also relatively common.
Create instantiation
The second stage is to create an instance. The main function of this stage is to create an instance object of the Bean through reflection.And will scan and parse some properties of the Bean name.When this step is completed, the Bean object has been created, but the Spring Bean is not used externally.
Dependency injection
The third stage is the dependency injection stage. If the instantiated bean depends on other beans, object injection needs to be performed on these dependent beans.For example, some configuration forms such as common @Autowired annotation injection or setter() injection in xml files.At the same time, some extension calls will be triggered at this stage, for example, the common extension class BeanPostProcessors post-processor is used to implement extension callbacks before and after Bean initialization, as well as BeanFactoryAware, etc.
Container cache
The fourth stage is the container cache stage. The main function of this stage is to save the beans in the container and Spring's cache.At this stage, the Bean can actually be called by the developer.The operations involved in this stage are common such as init-method, some methods configured by this property will be called in this stage; and post-processor methods like BeanPostProcessoes will also be triggered in this stage.
Destroy the instance
The fifth stage is to destroy the instance. When the Spring application context is closed, all the beans in the context will be destroyed. If there is a bean configurationThese methods of destroy-method will be called at this stage.
边栏推荐
猜你喜欢
随机推荐
李沐动手学深度学习V2-bert和代码实现
新增指令 v-memo
KDD 2022 | 深度图神经网络中的特征过相关:一个新视角
Which thread pool does Async use?
五大维度解读软件测试分类
基于 flex 布局实现的三栏布局
PLC工作原理动画
如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
Shell: conditional statements
你是几星测试/开发程序员?技术型选手王大拿......
[21 Days Learning Challenge] Bubble Sort and Insertion Sort
即时通讯开发移动端网络短连接的优化手段
【 LeetCode 】 1374. Generate each character string is an odd number
.NET性能优化-你应该为集合类型设置初始大小
网络协议介绍
【实战 已完结】WPF开发自动化生产管理平台
【StoneDB性能相关工具】内存监控
Digital twins help visualize the construction of smart cities
ImageNet下载及处理
交 叉 数 组