What is the difference between Spring singleton and singleton design pattern?

Solution

The Java singleton is scoped by the Java class loader whereas the Spring singleton is scoped by the container context. Which basically means that, in Java, you can be sure a singleton only within the context of the class loader which loaded it. Other class loaders should be capable of creating another instance of it. So, Java considers a singleton in a way that it cannot create more than one instance of that class within a given class loader, whereas Spring considers a singleton in a way that it cannot create more than one instance of a class within a given container/context.

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media