当前位置:网站首页>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

边栏推荐
- PHP直播源码实现简单弹幕效果的相关代码
- 电商库存系统的防超卖和高并发扣减方案
- R语言使用table1包绘制(生成)三线表、使用单变量分列构建三线表、编写自定义三线表结构(将因子变量细粒度化重新构建三线图)、自定义修改描述性统计参数输出自定义统计量
- 字节给我狠狠上了一课:危机来的时候你连准备时间都没有...
- For effective automated testing, these software testing tools must be collected!!!
- 【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
- 微信支付软件架构,这也太牛逼了!
- 哈希表
- C语言实验六 一维数组程序设计
- YGG 公会发展计划第 1 季总结
猜你喜欢
随机推荐
Kubernetes — 核心资源对象 — 存储
创新项目实战之智能跟随机器人原理与代码实现
Day115.尚医通:后台用户管理:用户锁定解锁、详情、认证列表审批
27英寸横置大屏+实体按键,全新探险者才是安全而合理的做法!
typescript34-class的基本使用
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
成都openGauss用户组招募啦!
飞桨开源社区季度报告来啦,你想知道的都在这里
电子制造仓储条码管理系统解决方案
飞桨助力航天宏图PIE-Engine地球科学引擎构建
C语言实验八 字符数组程序设计
H5画布 canvas(一)canvas简介、绘制圆形矩形、案例饼状图绘制
电商库存系统的防超卖和高并发扣减方案
Interview: Briefly describe a project you are involved in
3 Month Tester Readme: 4 Important Skills That Impacted My Career
canal实现mysql数据同步
After graduating from three books, I was rejected by Tencent 14 times, and finally successfully joined Alibaba
flask获取post请求参数
【刷题篇】打家劫舍
hash table









