@Scope – How to get Scope of Bean
@Scope – How to get Scope of Bean from Code
When we create a Bean we are creating actual instances of the class defined by that bean definition. We can also control the scope of the objects created from a particular bean definition.
There are 5 types of scopes in bean,
- singleton (default scope)
- prototype
- request
- session
- global-session
Singleton:
Single instance per spring IoC container
Prototype:
Single bean definition to any number of object instances.
Request:
Bean definition for each request. Only valid web-aware Spring ApplicationContext.
Session:
Bean definition for a session. Only valid web-aware Spring ApplicationContext.
Global-Session:
Similar to session but the only makes sense in the context of portlet-based web applications. Only valid web-aware Spring ApplicationContext.