Junior — Middle
Is it possible to implement multiple Singleton instances when using Spring for a single class?
sobes.tech AI
Answer from AI
In Spring, by default, beans are created with a singleton scope, meaning only one instance is created for a class within the container context.
However, if the scope of a bean is explicitly changed, for example to prototype, multiple instances of the same class can be obtained.
Also, if multiple Spring ApplicationContexts are created, each will have its own singleton instance.
Thus, within a single ApplicationContext, there will be one instance for a class with singleton scope, but using multiple contexts or different scopes can result in multiple instances.