Bird
0
0

You want to create a Bean that should be instantiated only once and shared across the application. Which scope should you use?

hard📝 Conceptual Q8 of 15
Spring Boot - Inversion of Control and Dependency Injection
You want to create a Bean that should be instantiated only once and shared across the application. Which scope should you use?
Aprototype
Brequest
Csingleton
Dsession
Step-by-Step Solution
Solution:
  1. Step 1: Understand Bean scopes in Spring

    Singleton scope means one instance per Spring container, shared everywhere.
  2. Step 2: Compare with other scopes

    Prototype creates new instance each time, request and session are web scopes.
  3. Final Answer:

    singleton -> Option C
  4. Quick Check:

    Single shared Bean = singleton scope [OK]
Quick Trick: Singleton scope creates one shared Bean instance [OK]
Common Mistakes:
  • Confusing prototype with singleton
  • Using request/session scopes outside web context
  • Assuming default is prototype

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes