spring中scope作用域(转)
今天研究了一下scope的作用域。默认是单例模式,即scope="singleton"。另外scope还有prototype、request、session、global session作用域。scope="prototype"多例。再配置bean的作用域时,它的头文件形式如下:
<bean id="role" class="spring.chapter2.maryGame.Role" scope="singleton"/>
这里的 scope 就是用来配置 spring bean 的作用域,它标识 bean 的作用域。
<bean id="role" class="spring.chapter2.maryGame.Role" scope="singleton"/>
或者
<bean id="role" class="spring.chapter2.maryGame.Role" singleton="true"/>
2、prototype
<bean id="role" class="spring.chapter2.maryGame.Role" scope="prototype"/>
或者
<beanid="role" class="spring.chapter2.maryGame.Role" singleton="false"/>
3、request
<web-app>
...
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
...
</web-app>
如果是Servlet2.4以前的web容器,那么你要使用一个javax.servlet.Filter的实现:
<web-app>
..
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>
接着既可以配置bean的作用域了:
<bean id="role" class="spring.chapter2.maryGame.Role" scope="request"/>
4、session
<bean id="role" class="spring.chapter2.maryGame.Role" scope="session"/>
5、global session
<bean id="role" class="spring.chapter2.maryGame.Role" scope="global session"/>
spring中scope作用域(转)的更多相关文章
- Spring中scope作用域
scope作用域: 1.prototype 2.request 3.session 4.singleton 5.global session 1.prototype(多例) prototyp ...
- spring中@Scope作用域的注解
@Scope简单点说就是用来指定bean的作用域 官方解释是:scope用来声明IOC容器中的对象应该处的限定场景或者说该对象的存活空间,即在IOC容器在对象进入相应的scope之前,生成并装配这些对 ...
- Spring中bean作用域属性scope
关键字: spring中属性scope的prototype是什么意思 默认情况下,从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spri ...
- spring中scope(作用越)理解
今天总结了一下spring中作用域scope的用法.在spring中作用域通过配置文件形式的用法如下. <bean id="role" class="spring. ...
- spring之scope作用域
spring中,bean的作用域有五种类型:默认是单例模式, singleton prototype request session ...
- 终于搞懂Spring中Scope为Request和Session的Bean了
之前只是很模糊的知道其意思,在request scope中,每个request创建一个新的bean,在session scope中,同一session中的bean都是一样的 但是不知道怎么用代码去验证 ...
- spring中@Scope控制作用域
注解形势:通过@Scope注解控制作用域,默认使用单实例模式,可修改为多实例模式 /** * Specifies the name of the scope to use for the annota ...
- spring中scope的prototype与singleton区别
最近在研究单例模式,突然想起项目中以下配置,scope="singleton" 和 scope="prototype"到底有何区别呢?以下做下简要分析. < ...
- Spring Bean Scope (作用域)
singleton: 单例模式,针对每个spring容器,只有一个该类的实例被管理,每次调用此实例都是同一个对象被返回,所以适用于无状态bean.默认情况下,singleton作为spring容器中b ...
随机推荐
- JQuery simpleModal插件的使用-遁地龙卷风
(0)写在前面 jquery.simpleModal.浏览器这三者的兼容性,不仅显示在报错上,还体现在所呈现的效果不是预期上. 说一下我的环境 jquery-1.8.3.js jquery.simpl ...
- 全架构PaaS TAE 2.0的Docker实践
推荐链接: http://www.infoq.com/cn/news/2015/07/paas-tae-docker
- mysql 按距离今日时间最近排序
xxx order by abs(DATEDIFF(time_start,now()))
- word20161201
http://baike.baidu.com/link?url=ZTTkA-suMlJNGb2AeNBE2E6MZQZwjkvWXKgmUpeLBIrCfC-k32cGJOJLrtDlLXjsTfkD ...
- java代码和spring框架读取xml和properties文件
1.java文件读取properties文件 Properties props = new Properties(); try { //资源文件存放在类文件的根目录下.即是放在src下面.则不需要写路 ...
- Internet与www的关系
Internet是把分布于世界各地不同结构的计算机网络用各种传输介质相互连接起来的网络. 因此,被称为网络的网络.Internet提供的主要服务有万维网(WWW.)文件传输(FTP.)电子邮件(E-m ...
- 2015安徽省赛 H.数7
http://xcacm.hfut.edu.cn/problem.php?id=1212 模拟大发 #include<iostream> #include<cstdio> #i ...
- 2 GPS utility methods
Methond 1 is to check whether the GPS is on: 1 2 3 4 5 public boolean isGPSIsOn() { LocationManager ...
- zend studio安装svn插件
进入zend->Help->Install New Software 输入如下地址: http://subclipse.tigris.org/update_1.8.x 选择subclips ...
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
在用php返回json数据的时候如果出现这种错误,先检查一下php中是否有使用var_dump()函数 这个函数会在页面输出测试变量的结构,浏览器会将这个当做json数据,所以就报错了....