Spring中的@scope注解
来源:互联网 发布:阿里云搭建ss教程 编辑:程序博客网 时间:2024/05/29 04:35
默认是单例模式,即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类型来使用。
阅读全文
0 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
- 九度题目1074:对称平方数
- jQuery和jQuery UI的区别
- 表示学习1-word2vec
- wampServer 启动报错
- Eclipse中怎么安装TestNG单元测试框架
- Spring中的@scope注解
- Linux下SGX的使用(2)-Hello Enclave
- Spring RedisTemplate操作-List操作
- Codeforces 856A
- POSIX定时器-线程方式创建定时器
- 第2章 UNIX标准及实现
- 深入理解 Java中的深克隆与浅克隆
- java_字符串中各类型字符出现的个数统计
- linux:一些压缩命令的使用