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 Scope | Description |
1. singleton | It 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. prototype | It scopes a single bean definition to have new bean instance each time a request for that particular bean is made. |
3. request | It scopes a bean definition to an HTTP request. |
4. session | It scopes a bean definition to an HTTP session. |
5. global-session | It 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.