Spring 框架根據在Spring context 中宣告bean的不同方式,來管理bean的生命週期。
在任何的Spring app中,都可以宣告一個bean為Singleton 模式和Prototype模式。
Singleton(單例模式)
Spring 中的預設的bean scope。由Spring 框架根據context中的唯一的bean的名字來區分每個bean的例項。
(The default bean scope in Spring, for which the framework uniquely identifies each instance with a name in the context。)
—reference <
Prototype(原型模式)
Spring 中的這種bean scope,當每次使用者請求呼叫這個bean的時候,Spring 框架只負責管理型別和建立新例項。
The bean scope in Spring, for which the framework only manages the type and creates a new instance of that class every time someone request it。(directly from the context or through wiring or auto-wiring)
SPRING FROM HERE