当前位置:网站首页>3. Bean scope and life cycle
3. Bean scope and life cycle
2022-08-02 01:41:00 【You really can't stop eating small dried fish】
Table of Contents
Scope Definition
The scope of a Bean refers to a certain behavior pattern of the Bean in the entire Spring framework, such as the singleton singleton scope, which means that there is only one copy of the Bean in the entire Spring, and it is globally shared, so when other people modify itAfter reading this value, what another person reads is the modified value.
6 scopes of beans
When the Spring container initializes an instance of a bean, it also specifies the scope of the instance.Spring has 6 scopes, the last four are based on Spring MVC:
\1. singleton: singleton scope --> Spring selects this scope by default
\2. prototype: prototype scope (multiple instance scope)
instance.
\3. request: request scope (a request-response scope)
\4. session: session scope (a session scope)
\5. application: global scope (understand)
\6. websocket: HTTP WebSocket scope (understand)
Note: The last four states are values in Spring MVC, and there are only the first two in a normal Spring project.

Bean execution process
Bean execution process (Spring execution process): start the Spring container -> instantiate the bean (allocate memory space, from scratch) -> register the bean in Spring (storage operation) -> assemble the bean to the required classin (fetch operation).
Bean Lifecycle
The life cycle of a bean is divided into the following 5 parts:
1. Instantiate Bean (allocate memory space for Bean, similar to new object)
2. Setting properties (Bean injection and assembly)
3.Bean initialization
3.1 implements various Aware notification methods, such as the interface methods of BeanNameAware, BeanFactoryAware, and ApplicationContextAware;
3.2 Execute BeanPostProcessor initialization pre-method;
3.3.1 Execute the @PostConstruct initialization method, which is executed after the dependency injection operation;
3.3.2 Execute the init-method method specified by yourself (if specified);
3.4 Execute the BeanPostProcessor initialization post method.
4. Use Bean
5. Destroy the Bean (the container can only be destroyed when the container is closed)
Execution process

边栏推荐
猜你喜欢

IDEA版Postman插件Restful Fast Request,细节到位,功能好用

秒懂大模型 | 3步搞定AI写摘要

go泛型使用方法

feign异常传递的两种方式 fallbackfactory和全局处理 获取服务端自定义异常

Debian侵犯Rust商标,妥协改名还是会得到豁免?

Image fusion based on weighted 】 and pyramid image fusion with matlab code

华为5年女测试工程师离职:多么痛的领悟...

三本毕业的我被腾讯拒绝了十四次,最终成功入职阿里

Flex layout in detail

Local storage in Kubernetes
随机推荐
C语言实验八 字符数组程序设计
秒懂大模型 | 3步搞定AI写摘要
Interview: Briefly describe a project you are involved in
When paying attention to the "Internet +" model, you usually only focus on the "Internet +" model itself
datax与datax-web安装部署
GO GOPROXY代理设置
dayjs时间处理库的基本使用
YGG Guild Development Plan Season 1 Summary
ALCCIKERS Shane 20191114
R语言使用cph函数和rcs函数构建限制性立方样条cox回归模型、使用anova函数进行方差分析通过p值确认指定连续变量和风险值HR之间是否存在非线性关系
Test Cases: Four-Step Test Design Approach
Rust P2P网络应用实战-1 P2P网络核心概念及Ping程序
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
Kubernetes — Calico
PHP直播源码实现简单弹幕效果的相关代码
Pytorch seq2seq model architecture to achieve English translation tasks
mapbox使用教程
浅谈国产ERP的“横纵竖”三向发展态势
ofstream,ifstream,fstream读写文件
设备树学习