Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic