懒得笔记3 spring bean 的生存范围 生命周期
来源:互联网 发布:淘宝签署图片空间协议 编辑:程序博客网 时间:2024/04/29 00:30
1,生存范围
singleton
(Default) Scopes a single bean definition to a single object instance per Spring IoC container.
prototype
Scopes a single bean definition to any number of object instances.
request
Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext
.
session
Scopes a single bean definition to the lifecycle of an HTTP Session
. Only valid in the context of a web-aware Spring ApplicationContext
.
global session
Scopes a single bean definition to the lifecycle of a global HTTP Session
. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext
.
application
Scopes a single bean definition to the lifecycle of a ServletContext
. Only valid in the context of a web-aware Spring ApplicationContext
.
bean 中scope 的属性
1, singleton 单例,默认值 ,不管new 多少次,取到的都是同一个对象。
UserService service = (UserService)ctx.getBean("userService");UserService service2 = (UserService)ctx.getBean("userService");System.out.println(service == service2);//为true
2, prototype 原型 每次取到的不一样 struts 里面action 用这个 官方推荐,
2,生命周期
默认情况下,每次启动都会将所有bean生成放在内存中。
1,lazy-initialized (一般不用到)
context 声明时进行初始化,在get的时候再进行初始化
<bean id="lazy" class="com.foo.ExpensiveToCreateBean" lazy-init="true"/><bean name="not.lazy" class="com.foo.AnotherBean"/>
设置所有的bean
<beans default-lazy-init="true"> <!-- no beans will be pre-instantiated... --></beans>
2,
init-method destroy-methd
不要和
prototype
一起用(了解)
init-method destroy-methd
不要和
prototype
一起用(了解)
init-method destroy-methd 不要和prototype一起用(了解)
两个属性可以在定义bean在初始化和destroy时调用的方法。
- 懒得笔记3 spring bean 的生存范围 生命周期
- spring学习之bean的生存范围和生命周期
- Spring——自定义属性编辑器+Bean的生存范围+Bean的生命周期
- spring——bean的生存范围
- Spring scope bean生存范围
- spring bean 的生存范围 单例 还是原型
- spring bean 的生存范围 单例 还是原型
- spring bean 的生存范围 单例 还是原型
- Spring Bean的范围
- spring学习笔记2---bean的生命周期
- Spring 学习笔记---Bean的生命周期
- Spring学习笔记----Bean的生命周期
- spring笔记——bean的生命周期
- spring 笔记5 bean的生命周期,BeanPostProcessor
- Spring 学习笔记---Bean的生命周期
- Spring学习笔记之---bean的生命周期
- Spring Bean的生存日记
- Spring中的IOC(三):bean 的其他属性及bean实例的生命周期和范围
- 1.excle学习之一:工作环境设置
- C/C++获取当前系统时间
- jquery each报 Uncaught TypeError: Cannot use 'in' operator to search for错误
- 带权最短路 Dijkstra, SPFA, Bellman-Ford, ASP, Floyd-Warshall 算法分析
- Android下拉刷新组件
- 懒得笔记3 spring bean 的生存范围 生命周期
- Eddy's research I
- UE3 移动设备主页
- 1033. 旧键盘打字(20):map中count用法以及gets读空串
- Centos平台下SVN的权限管理
- 黑马程序员——OC笔记之Foundation框架上
- 关于Frame和Bounds的相关问题
- 黑马程序员———C语言———【指针】
- Virtual Box 怎么重复使用虚拟硬盘文件.vdi