当前位置:网站首页>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.
边栏推荐
猜你喜欢

Day35 LeetCode

线程安全(上)

广东省数字经济发展指引 1.0之建成数据安全保障体系

Electron User Guide Beginning Experience

Parse the commonly used methods in the List interface that are overridden by subclasses

【SLAM】DM-VIO(ros版)安装和论文解读

Introduction of uncommon interfaces of openlayers

牛客题目——滑动窗口的最大值、矩阵最长递增路径、顺时针旋转矩阵、接雨水问题

KDD 2022 | 深度图神经网络中的特征过相关:一个新视角

SQL Server安装教程
随机推荐
Lvm逻辑卷
五大维度解读软件测试分类
In action: 10 ways to implement delayed tasks, with code!
基于 flex 布局实现的三栏布局
Likou Question of the Day - Day 46 - 344. Reverse Strings
如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
遇上Mysql亿级优化,怎么办
2170. 使数组变成交替数组的最少操作数
实现fashion_minst服装图像分类
【LeetCode】622. 设计循环队列
姑姑:给小学生出点口算题
Tencent YunMeng every jie: I experienced by cloud native authors efficiency best practices case
golang source code analysis: uber-go/ratelimit
信息学奥赛一本通(1259:【例9.3】求最长不下降序列)
Geoserver+mysql+openlayers2
Axure9的元件用法
Xcode13.1运行工程报错fatal error: ‘IFlyMSC/IFly.h‘ file not found的问题
Golang source code analysis: time/rate
【 LeetCode 】 1374. Generate each character string is an odd number
C# Monitor类