Announcement Announcement Module
Collapse
No announcement yet.
Query about Bean scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query about Bean scope

    Hi All,
    I have a question about bean scoping.

    As per my understanding spring container loads all beans declared in springContext.xml(application context in my case) when application get started.

    Now in case of prototype bean, for each request to a particular bean I am getting a complete new object. This mean that container is creating a new bean(object) at run time.

    So it would be helpful if anyone can explain me the exact working behaviour of spring container.

    Thanks in advance.

  • #2
    Singleton beans are created on startup by default (you can use "lazy" attribute to create them when they are accessed for the first time). There is only one instance of each singleton of course.
    As you said, prototype scope means that a new instance of a bean is created every time when it is requested (ctx.getBean(..), injection into another bean).
    Other scopes that Spring provides are bound to some resource, like http request or session. It means e.g. that for the same http request, the same instance of bean is always returned when requested.
    It is described in detail in the Spring reference documentation, here.

    Comment


    • #3
      thanks libor :-)

      Comment

      Working...
      X