Sunday, 16 April 2017

Spring: Bean Scopes

Spring framework supports seven bean scopes. Out of these seven, five (request, session, globalSession, application, websocket) scopes are only if you use a web-aware ApplicationContext.

Following table summarizes the bean scopes

Scope
Description
singleton
It is the default scope. Spring IOC container create single instance of the class and return the same instance on all subsequent requests.
prototype
It return new bean instance on each time when requested.
request
Each HTTP request has its own instance of a bean. Only valid in the context of a web-aware Spring ApplicationContext.
session
Single bean instance is returned per session. Only valid in the context of a web-aware Spring ApplicationContext.
globalSession
Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a Portlet context. Only valid in the context of a web-aware Spring ApplicationContext.
application
Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.
websocket
Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext.


My subsequent posts explain about each scope in detail.



Previous                                                 Next                                                 Home

No comments:

Post a Comment