Announcement Announcement Module
Collapse
No announcement yet.
order the beans are loaded? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    #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

    Comment

    Working...
    X