What is the default scope of a Spring bean?
Options
- Prototype: a new instance on every injection
- Singleton: one shared instance per application context (Correct option)
- Request: one instance for each HTTP request
- Session: one instance for each logged-in user
Answer
Singleton: one shared instance per application context
Why
By default Spring creates ONE instance of each bean and shares it everywhere (singleton scope; not the GoF pattern, but one per container).
Because many threads use the same object, singleton beans should be stateless: avoid mutable fields that change per request.
Other scopes exist (prototype, request, session) but are rarely needed.
Remember
Beans are singletons by default, so keep them stateless.