0

Singleton means Single object for a class.In spring we can create multiple beans for same class (bean is nothing but an object) using singleton scope.For example see the below code

   <bean id="abc" class="com.test.Abc"/>
   <bean id="def" class="com.test.Abc"/>

In this scenario spring will create 2 singletons (I have refereed some SO links).How we can call it as singleton , because more than one object is created for the same class.

As per the definition

The Singleton's purpose is to control object creation, limiting the number of objects to only one. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class.

PSR
  • 39,804
  • 41
  • 111
  • 151

1 Answers1

1

Each bean is a singletone, no matter how many times u create the same bean ( as long as the scope is set to default or singleton) you will only have on object . It makes since for 2 beans with the same type to create different object as you may set different constructor params or properties

Amer Qarabsa
  • 6,412
  • 3
  • 20
  • 43