beginnerBeans, Configuration & Lifecycle
What is the default bean scope in Spring, and when would you use `prototype` instead?
The default scope is `singleton` — exactly one instance per Spring container, shared by every injection point. `prototype` creates a brand-new instance every time the bean is requested, which matters for stateful, non-thread-safe objects (e.g. a mutable builder-like helper) where sharing one instance across concurrent requests would cause data races.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response