当前位置:网站首页>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
边栏推荐
猜你喜欢
字节给我狠狠上了一课:危机来的时候你连准备时间都没有...
Why is on-chain governance so important, and how will Polkadot Gov 2.0 lead the development of on-chain governance?
外包干了三年,废了...
6-24 exploit-vnc password cracking
ofstream,ifstream,fstream读写文件
go泛型使用方法
理解分布式系统中的缓存架构(下)
哈希表
Interview: Briefly describe a project you are involved in
6-25漏洞利用-irc后门利用
随机推荐
mapbox使用教程
Rust P2P网络应用实战-1 P2P网络核心概念及Ping程序
Redis cluster mode
Navicat数据显示不完全的解决方法
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
Image fusion based on weighted 】 and pyramid image fusion with matlab code
Kubernetes — 网络流量模型
typescript33-typescript高级概述
有效进行自动化测试,这几个软件测试工具一定要收藏好!!!
ALCCIKERS Shane 20191114
Flex布局详解
flask获取post请求参数
6-25 Vulnerability Exploitation - irc Backdoor Exploitation
Local storage in Kubernetes
Reflex WMS中阶系列7:已经完成拣货尚未Load的HD如果要取消拣货,该如何处理?
H5画布 canvas(一)canvas简介、绘制圆形矩形、案例饼状图绘制
6-24漏洞利用-vnc密码破解
A full set of common interview questions for software testing functional testing [open thinking questions] interview summary 4-3
Kubernetes — 核心资源对象 — 存储
TKU记一次单点QPS优化(顺祝ITEYE终于回来了)