Spring / Spring7 basics Interview questions
What are the types of bean scopes in Spring?
Bean scope defines how many instances of a bean the container creates and how long each one lives.
| Scope | Lifetime |
| singleton | One shared instance per container (the default) |
| prototype | A new instance every time the bean is requested |
| request | One instance per HTTP request (web-aware contexts) |
| session | One instance per HTTP session |
| application | One instance per ServletContext |
singleton and prototype are always available; request, session, and application only apply in a web-aware ApplicationContext. Scope is set with @Scope("prototype") or the equivalent XML attribute.
More Related questions...