Spring ApplicationContext Bean Scope [英] Spring ApplicationContext Bean Scope

查看:93
本文介绍了Spring ApplicationContext Bean Scope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring applicationContext.xml文件中创建Service bean或Dao bean时,这些bean的范围是什么?

When you create a Service bean or Dao bean in your Spring applicationContext.xml file, what is the scope of those beans?

访问Web应用程序的每个人都会使用相同的bean实例,还是为每个用户的会话实例化了bean?

Will every person who accesses the web application use the same instance of the bean, or is the bean instantiated for each user's session?

推荐答案

默认情况下,在Spring中创建的bean的范围是 singleton ,因此,在这些情况下,每个人都将访问同一个实例。另一种方法是将范围指定为原型

By default a bean created in Spring is of scope singleton, so yes each person will access the same instance in those cases. The alternative is to specify the scope as prototype.

此处有更多信息,第3.4.1和3.4.2节:

More info on this here, sections 3.4.1 and 3.4.2:

http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes-prototype

这篇关于Spring ApplicationContext Bean Scope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆