In this tutorial we are going to see the overview of Spring bean scope.
When you create bean definition in Spring, you can declare the scope of bean.
You can control not only the various dependencies and configuration values that are to be plugged into an object that is created from a particular bean definition, but also the scope of the objects created from a particular bean definition. This approach is powerful and flexible in that you can choose the scope of the objects you create through configuration instead of having to bake in the scope of an object at the Java class level. Beans can be defined to be deployed in one of a number of scopes: out of the box, the Spring Framework supports five scopes, three of which are available only if you use a web-aware ApplicationContext.
You can also create custom scope . we will see this in upcoming chapter.
The following scopes are supported by Spring.
Bean Scopes
Thread-scope beans :
As of Spring 3.0, a thread scope is available, but not register by default.we will see how to register this or any other custom scope in upcoming chapter.
When you create bean definition in Spring, you can declare the scope of bean.
You can control not only the various dependencies and configuration values that are to be plugged into an object that is created from a particular bean definition, but also the scope of the objects created from a particular bean definition. This approach is powerful and flexible in that you can choose the scope of the objects you create through configuration instead of having to bake in the scope of an object at the Java class level. Beans can be defined to be deployed in one of a number of scopes: out of the box, the Spring Framework supports five scopes, three of which are available only if you use a web-aware ApplicationContext.
You can also create custom scope . we will see this in upcoming chapter.
The following scopes are supported by Spring.
Bean Scopes
Scope
|
Description
|
singleton | (Default) Scopes a single bean definition to a single object per Spring IoC container. |
prototype | Scopes a single bean definition to any number of object instance. |
request | Scopes a single bean definition to the lifecycle of single HTTP request, that is, each HTTP request has its own instance of bean created off the back of single bean definition. Only valid in the context of a web-aware Spring ApplicationContext. |
session | Scopes a single bean definition to the lifecycle of HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext. |
global session | Scopes a single bean definition to the lifecycle of global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring application context. |
As of Spring 3.0, a thread scope is available, but not register by default.we will see how to register this or any other custom scope in upcoming chapter.
0 comments:
Post a Comment