Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Spring, singleton is the default bean scope: one managed instance is created for a bean definition in each Spring IoC container, and later requests from that container reuse it. That does not mean one instance for the whole JVM, and it does not make the bean thread-safe.

What does singleton scope mean in Spring?

Spring’s reference defines singleton scope as one object instance for each bean definition in each Spring IoC container. The container creates the bean once and caches it, so lookups of that bean definition through the same container return the shared instance. See the Spring bean scopes reference.

The scope is per bean definition and per container—not a JVM-wide guarantee. If two separate Spring containers each manage the same bean definition, each container can have its own instance.

Is a Spring singleton the same as the Singleton design pattern?

No. The GoF Singleton design pattern constrains object construction in the class or its creation mechanism; Spring singleton scope is a container-managed choice applied to a bean definition. Spring describes the GoF pattern’s scope as one instance per ClassLoader, while its own singleton scope is per container and per bean. The distinction is explained in the Spring singleton scope documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Are singleton beans thread-safe?

Singleton scope guarantees shared identity within the container, not safe concurrent access. Multiple callers may use the same object at the same time. A stateless bean or one with immutable state is often straightforward to share; mutable fields require deliberate concurrency design, such as confinement or appropriate synchronization. Scope alone adds no thread-safety protection.

What happens when a singleton injects a prototype bean?

With ordinary dependency injection, Spring resolves the prototype dependency when it creates and assembles the singleton. The singleton then holds that particular prototype object; injecting it does not request a fresh object on every method call. Spring notes that the container creates the singleton only once and therefore has one opportunity to set its properties: prototype scope and singleton dependencies.

If the singleton needs a new prototype for each operation, request it at runtime using method injection or a provider/lookup approach. This separates the singleton’s stable lifetime from the prototype’s repeated creation.

How does singleton scope compare with other Spring scopes?

Scope Instance behavior Typical use or constraint
Singleton One instance per bean definition per container. Shared service or other object whose state is stateless, immutable, or safely coordinated.
Prototype A new instance for each request to the container. Objects needing independent state. A singleton’s ordinary injected reference is still the one resolved at singleton creation.
Request/session-style web scopes Instance lifetime is associated with the relevant request or session. Requires a web-aware context; these scopes are tied to their documented web lifecycle.

Spring documents these scope definitions and the web-context requirement in its scope reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What lifecycle should you describe in an interview?

For a typical singleton, explain the sequence rather than implying that scope is a design pattern: the IoC container creates the bean, assembles it and injects dependencies, invokes applicable initialization callbacks after configuration, makes it available for use through the application context, and handles destruction when the context closes. Spring’s lifecycle documentation describes dependency assembly before lifecycle callbacks: Spring bean lifecycle and callbacks.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A concise interview answer

“Singleton is Spring’s default bean scope. It gives one managed instance per bean definition per IoC container, not one instance for the entire JVM. It is not the same as the GoF Singleton pattern, and shared scope does not make mutable state thread-safe. If a singleton has a prototype dependency, ordinary injection resolves it when the singleton is created; to obtain a fresh prototype later, use a provider or lookup mechanism.”

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.