This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring default bean scope is singleton. why?

 
Pankaj Kr. Singh
Ranch Hand
Posts: 32
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

As we know that the default a bean scope of bean in Spring framework is Singleton.
So, why it is Singleton why not other like prototype etc.
Please help me...

Thanks
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Default scope is singleton to make sure that minimum number of objects are created during bean factory instantiation.
If single bean instance does not fit into specific scenario, user can choose to set beans scope as prototype.
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Salil's answer. That is the advantage of Spring. There is difference between Spring's singleton and Java singleton object.
It creates very less amount of objects in memory.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic