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

边栏推荐
猜你喜欢
随机推荐
Use flex-wrap to wrap lines in flex layout
go泛型使用方法
去经营企业吧
iframe使用
Kubernetes — 核心资源对象 — 网络
NFT到底有哪些实际用途?
Day11 Shell scripting basics
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
当关注「互联网+」模式的时候,通常仅仅只是在关注「互联网+」模式本身
Navicat数据显示不完全的解决方法
【图像融合】基于加权和金字塔实现图像融合附matlab代码
3.Bean的作用域与生命周期
feign异常传递的两种方式 fallbackfactory和全局处理 获取服务端自定义异常
牛顿定理和相关推论
Redis和MySQL数据一致性问题,有没有好的解决方案?
喜报 | AR 开启纺织产业新模式,ALVA Systems 再获殊荣!
电商库存系统的防超卖和高并发扣减方案
S/4中究竟有多少个模块,你对这些模块了解多少
电子制造仓储条码管理系统解决方案
6-25漏洞利用-irc后门利用









