File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change 36
36
37
37
### 1. singleton——唯一 bean 实例
38
38
39
- ** 当一个 bean 的作用域为 singleton,那么Spring IoC容器中只会存在一个共享的 bean 实例,并且所有对 bean 的请求,只要 id 与该 bean 定义相匹配,则只会返回bean的同一实例。** singleton 是单例类型(对应于单例模式),就是在创建起容器时就同时自动创建了一个bean的对象,不管你是否使用,他都存在了, 每次获取到的对象都是同一个对象。注意,singleton 作用域是Spring中的缺省作用域。要在XML中将 bean 定义成 singleton ,可以这样配置:
39
+ ** 当一个 bean 的作用域为 singleton,那么Spring IoC容器中只会存在一个共享的 bean 实例,并且所有对 bean 的请求,只要 id 与该 bean 定义相匹配,则只会返回bean的同一实例。** singleton 是单例类型(对应于单例模式),就是在创建起容器时就同时自动创建了一个bean的对象,不管你是否使用,但我们可以指定Bean节点的 ` lazy-init=”true” ` 来延迟初始化bean,这时候,只有在第一次获取bean时才会初始化bean,即第一次请求该bean时才初始化。 每次获取到的对象都是同一个对象。注意,singleton 作用域是Spring中的缺省作用域。要在XML中将 bean 定义成 singleton ,可以这样配置:
40
40
41
41
``` xml
42
42
<bean id =" ServiceImpl" class =" cn.csdn.service.ServiceImpl" scope =" singleton" >
@@ -446,4 +446,4 @@ this is destory of lifeBean com.bean.LifeBean@573f2bb1
446
446
- https://blog.csdn.net/fuzhongmin05/article/details/73389779
447
447
- https://yemengying.com/2016/07/14/spring-bean-life-cycle/
448
448
449
- 由于本文非本人独立原创,所以未声明为原创!在此说明!
449
+ 由于本文非本人独立原创,所以未声明为原创!在此说明!
You can’t perform that action at this time.
0 commit comments