spring bean scopes examples

Spring bean scopes:

As we discussed that spring container is responsible for creating and managing bean object. Spring provides the facility to return the same instance or a new instance each time when one is needed. It depends upon the bean scope.

Spring framework bean scopes:

Bean ScopeDescription
1. singletonIt scopes the bean definition to a single instance per spring container. It is the default scope. Spring container keeps it into cache and returns the same instance each time a request for that particular bean is made.
2. prototypeIt scopes a single bean definition to have new bean instance each time a request for that particular bean is made.
3. requestIt scopes a bean definition to an HTTP request.
4. sessionIt scopes a bean definition to an HTTP session.
5. global-sessionIt scopes a bean definition to a global HTTP session.
 
Note: The request, session and global-session are only available in the context of a web-aware ApplicationContext.

No comments: