1.Singleton Scope:(Default)
Scopes a single bean definition to a single onject instance per IOC container.
eg:
<bean id="helloWorldService"
class="com.searchendeca.application.HelloWorld">
<constructor-arg value="Welcome to Search Endeca" scope="singleton" />
<!-- <property name="greet" ref="helloGreeting" />-->
</bean>
2.Prototype:
Scopes a single bean definition to any number of object instances.
3.Request:
Scopes a single bean definition to the lifecycle of a single HTTP request, that is each HTTP request
has its own instance of a bean created of a single bean definition.
4.Session:
Scopes a single bean definition to the lifecycle of an HTTP Session.
5.Global Session:
Scope a single bean definition the lifecycle of a global HTTP Session.
6.Application:
Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of
a web-aware Spring ApplicationContext.
Some Important points to be remembered here.
Singleton beans with prototype-bean dependencies
When you use singleton-scoped beans with dependencies on prototype beans, be aware that
dependencies are resolved at instantiation time.
Thus if you dependency-inject a prototype-scoped bean
into a singleton-scoped bean, a new prototype bean is instantiated and then dependency-injected into
the singleton bean. The prototype instance is the sole instance that is ever supplied to the singletonscoped bean.
Request, session, and global session scopes
The request, session, and global session scopes are only available if you use a web-aware
Spring ApplicationContext implementation (such as XmlWebApplicationContext).
No comments:
Write comments