aspose file tools*
The moose likes Spring and the fly likes Spring default bean scope is singleton. why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring default bean scope is singleton. why?" Watch "Spring default bean scope is singleton. why?" New topic
Author

Spring default bean scope is singleton. why?

Pankaj Kr. Singh
Ranch Hand

Joined: Mar 31, 2011
Posts: 32

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

Joined: Sep 06, 2009
Posts: 255

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.

Regards
Salil Verma
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

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.


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring default bean scope is singleton. why?