Announcement Announcement Module
Collapse
No announcement yet.
Container - Loading references at runtime Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Container - Loading references at runtime

    All,

    I am new to spring and learnt the concepts and trying to use them in a small project .
    Please advise me on the below clarifications ,

    I have created an xml to be used by my application , and I use ClassPathXmlApplicationContext to load the xml in my main method .
    Will the container load all the references/beans that my xml carries as soon as new ClassPathXmlApplicationContext is called in main ? Even though I may not need all the reference ?
    If the above statement is true should we created multiple xml files and load them separately whenever needed ?
    I also have created a factory using springs org.springframework.beans.factory.config.ServiceLo catorFactoryBean
    and objects are instantiated at runtime in that case how can i effectively load only the references for that instantiated class at runtime ?

  • #2
    Spring creates all bean object instances and load them when it complete the creation of application context using ClassPathXmlApplicationContext. This is the default behavior.
    All bean definition configuration in the XML application context file, it will create bean object instances up-front and all all are part of the container.

    You can write separate different application context files, but it is recommended to have one master configuration file and create one spring application context container per application. If you load them separately, you will loose some of the spring features. It is not recommended to load them separately.

    All Spring specific beans that are part of XML configuration will get created during ClassPathXmlApplicationContext creation time.

    Comment

    Working...
    X