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

Next Step

Continue to What's the correct way to run code right after a bean's dependencies are injected?← Back to all Spring Boot questions