Loading
Spring Bean Scopes-interview

Q1. What is a Bean Scope in Spring?

A Bean Scope defines how many instances of a bean Spring should create and how long they should live inside the application.

It answers:

  • How many bean objects will be created
  • When will these objects be created and destroyed


Q2. How many bean scopes does Spring support? Which are the most commonly used?

Spring supports six scopes:

1. Singleton (default)
2. Prototype
3. Request
4. Session
5. Application
6. WebSocket

Commonly used

Singleton, Prototype, Request, Session.


Q3. What is singleton scope? Why is it the default?

Spring creates one object of the bean for the whole application context.
Every injection receives the same instance.

It is default because most beans (services, repositories) are stateless, so sharing a single instance is efficient and memory-friendly.


Q4. When should you use prototype scope?

Use Prototype when:

  • You need stateful objects
  • You want a new object per request
  • You need temporary or short-lived objects

Example: Creating a new Task object for every job request.


Q5. How does Spring behave differently in Web Applications?

Spring provides web-specific scopes:

  • Request → one instance per HTTP request
  • Session → one instance per browser session
  • Application → one instance per ServletContext
  • WebSocket → one instance per WebSocket session

These help manage request and session-level data.