Announcement Announcement Module
No announcement yet.
what is singleton in Spring? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • what is singleton in Spring?

    Hi ,

    can somebody explained what is the purpose/benefit of singleton in Spring
    in real worl analogy ?

    I know a lot people saying that singleton means per application context.

    If i have a static variable on my jsp page.
    will singleton=false will keep initialise the variable everytime i re visit the page?


  • #2
    Hi Kid

    (I am assuming that you have read that section of the Spring reference manual that details the various scopes, including the section devoted specifically to the singleton scope.)

    If you want a brand spanking new bean (Spring-managed object) for each and every distinct request in your web application, you need the request scope introduced in Spring 2.0.

    Perhaps if you explained in a little more depth what it is you are trying to do someone will be able to provide a more pertinent answer.



    • #3
      Typically business objects are singleton, for example, the object that contains operations to database, are singleton objects. All operations that doesn't need state after its execution, like conversion tools, math operations, signing data, encrypt data, ... are singleton too.

      In 90 % of cases a singleton approach is the best.


      • #4
        Perhaps this thread will help explain, if the Spring documentation 2.0 does not explain it better: