Results 1 to 2 of 2

Thread: order the beans are loaded?

  1. #1
    Join Date
    Jul 2006
    Posts
    22

    Default order the beans are loaded?

    This seems to be a very simple questions, but I haven't been able to find a definitive answer in the Spring's manual,

    1) Is there any guarantee that the container will load independent beans in the order they are declared in the XML file?

    2) Are beans instantiated as well (both singleton and prototype) as soon as they are loaded by the container?

    3) How does Spring container finds the dependencies between beans if they are not declared in order?

    4) Are beans by default lazily-loaded by the BeanFactory? In that case the order wouldn't matter - isn't it?

    5) When using "ClassPathXMLApplicationContext" to load multiple files, is the order we specify the xml files in the list important? That is, would the beans in the first xml file load before the others?

    <bean id="server.context" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>applicationContext-server-service.xml</value>
    <value>applicationContext-manager.xml</value>
    <value>applicationContext-client.xml</value>
    </list>
    </constructor-arg>
    </bean>
    </beans>

    I want to make sure the beans are loaded in order. I can use Parent-Child beans relation, but want to see if the ClassPathXMLApplicationContext could work too.

    Thanks.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    #1 No

    #2 That depends on the type of bean and if they are declared lazy or not

    #3 It checks the dependencies of the beans in the xml files, although it's starting point isn't always the same, it just takes a bean and goes from there.

    #4 No, only beans declared lazy.

    #5 No
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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