Web tier: servlets, JSP, Web frameworks: Spring Framework and singleton objects

  1. Spring Framework and singleton objects (3 messages)

    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.


    Threaded Messages (3)

  2. 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.

  3. Why ?[ Go to top ]

    Thanks for your reply.
    But why each bean is singleton ? All controllers and everything else is singleton. Is there a reason behind this ?
  4. Hi, You can take a look to this article that is treating Singleton injection with spring. Nabil