Spring上下文中的有状态Bean和无状态Bean [英] Stateful beans and Stateless beans in Spring context
问题描述
我正在阅读Spring的官方文档,有一次我来到了一行,它对所有有状态的bean使用原型范围,而对无状态的bean使用单例.
I am reading spring through its official documentation and at one place I came to a line that uses prototype scope for all stateful beans while singleton for stateless beans.
我知道EJB中有无状态bean以及无状态bean,但这不是它们在文档中提到的.
I know there is something as stateful as well as stateless beans in EJB but this is not what they have mentioned in the documents.
任何人都可以向我解释在春天,有状态和无状态bean到底意味着什么
Can anyone explain to me what exactly this means of stateful as well stateless beans in Spring
预先感谢
推荐答案
从春季的角度来看
-
无状态bean:单例且仅初始化一次的bean.他们具有的唯一状态是共享状态.这些Bean是在
ApplicationContext
初始化时创建的.在此ApplicationContext
的生存期内,将返回/注入SAME bean实例.
stateless beans: beans that are singleton and are initialized only once. The only state they have is a shared state. These beans are created while the
ApplicationContext
is being initialized. The SAME bean instance will be returned/injected during the lifetime of thisApplicationContext
.
有状态bean:可以携带状态(实例变量)的bean.这些是在每次需要对象时创建的(例如在Java中使用"new"运算符).
stateful beans: beans that can carry state (instance variables). These are created EVERY time an object is required (like using the "new" operator in java).
这些不是EJB statfull/无状态会话bean.
These are not EJB statfull/stateless session beans.
这篇关于Spring上下文中的有状态Bean和无状态Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!