Results 1 to 3 of 3

Thread: Query about Bean scope

  1. #1
    Join Date
    Aug 2011
    Posts
    5

    Default 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. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    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.

  3. #3
    Join Date
    Aug 2011
    Posts
    5

    Default

    thanks libor :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •