- Posted by: Vinay Gajjar
- Posted on: July 27 2005 12:57 EDT
I recently started using spring after reading lots of good articles about it. I have gone through examples provided with spring downloads.
The one thing that confused me is about the singleton objects. If we dont specify what kind of object it is, it will default to singleton. And the jpetstore example that comes with distribution, I checked all of its bean configuration files, none of them specify attribute "singleton" . Does that mean every object is siglton ? I also read in one of the articles. It was saying : "Singleton in that application context only." What does that mean ?
Please give me an idea about this.
By default all beans in Spring are singletons. To have a bean which will not be instantiated as a singleton, use singleton="false" in the configuration of the bean. If none of the beans in the jpetstore example make this specification then they are all singletons.
Thanks for your reply.
But why each bean is singleton ? All controllers and everything else is singleton. Is there a reason behind this ?
Hi, You can take a look to this article that is treating Singleton injection with spring. Nabil