View RSS Feed

Spring Framework

Spring Bean Scopes

Rate this Entry
by , 07-07-2012 at 05:44 PM (1006 Views)
You can easily declare the bean scope for the bean when you define a bean in Spring. Whenever a new bean instanace is required by you, bean scope attribute is declared as prototype to force the Spring to produce the bean instance. Also whenever you are looking for the same bean instance from the Spring, the bean scope instance is declared as singleton.
The following five scopes are supported by the Spring framework. In case of a web aware ApplicationContext, only three scopes are available.

singleton: Only one instance of a bean is possible for one SpringIoC container.
prototype: In this scope a single bean instance may have more than one object instances.
request: An HTTP request is a bean definition in this scope. It is only valid for a web based Spring ApplicationContext.
session: An HTTP session is a bean definition in this scope. It is also only valid for a web aware Spring ApplicationContext.
global-session: A global HTTP session is a bean definition in this scope. This scope is also only valid for a web aware Spring ApplicationContext.

Submit "Spring Bean Scopes" to Facebook Submit "Spring Bean Scopes" to Digg Submit "Spring Bean Scopes" to del.icio.us Submit "Spring Bean Scopes" to StumbleUpon Submit "Spring Bean Scopes" to Google

Categories
Bean

Comments