Spring中的@scope注解
来源:互联网 发布:mac zookeeper 客户端 编辑:程序博客网 时间:2024/05/29 00:33
Spring中的@scope注解
默认是单例模式,即scope="singleton"。另外scope还有prototype、request、session、global session作用域。scope="prototype"多例
@scope默认是单例模式(singleton)
如果需要设置的话@scope("prototype")
1.singleton单例模式,
全局有且仅有一个实例
2.prototype原型模式,
每次获取Bean的时候会有一个新的实例
3.request
request表示该针对每一次HTTP请求都会产生一个新的bean,同时该bean仅在当前HTTP request内有效,配置实例:
request、session、global session使用的时候首先要在初始化web的web.xml中做如下配置:
如果你使用的是Servlet 2.4及以上的web容器,那么你仅需要在web应用的XML声明文件web.xml中增加下述ContextListener即可:
1
2
3
4
5
6
7
<web-app>
...
<listener>
<listener-
class
>org.springframework.web.context.request.RequestContextListener</listener-
class
>
</listener>
...
</web-app>
4.session
session作用域表示该针对每一次HTTP请求都会产生一个新的bean,同时该bean仅在当前HTTP session内有效
5.global session
global session作用域类似于标准的HTTP Session作用域,不过它仅仅在基于portlet的web应用中才有意义。Portlet规范定义了全局Session的概念,它被所有构成某个 portlet web应用的各种不同的portlet所共享。在global session作用域中定义的bean被限定于全局portlet Session的生命周期范围内。如果你在web中使用global session作用域来标识bean,那么web会自动当成session类型来使用。
原文: http://www.cnblogs.com/lonecloud/p/5745902.html
阅读全文
1 0
- Spring中的@scope注解
- Spring中的@scope注解
- Spring中的@scope注解
- Spring中的@scope注解
- Spring中的scope配置和@scope注解
- Spring注解@Scope("prototype")
- Spring注解@Scope("prototype")
- Spring注解@Scope("prototype")
- Spring注解之@Scope("prototype")
- Spring 中的 Bean Scope
- spring中的scope
- Spring中的Scope详解
- spring中的scope
- spring中的scope
- spring中的scope详解
- Spring配置文件中的Scope
- spring中的属性scope
- Spring中的Scope
- JavaEE实现WebSocket(二)使用SpringMvc和AngularJS
- 43. Multiply Strings
- SQL复杂语句
- windows下安装配置mongodb
- Thinking In Java习题作业集
- Spring中的@scope注解
- 论理想中的技术团队——领导力
- 区块链(三)--常用命令(1)
- JS无缝滚动,form表单获取数据异常多,符号
- python的time.time()处理方法
- string 转换成 char*
- struts2中action执行两次
- h5项目如何打成war包
- java入门-构造函数和构造代码块功能