Spring framework can instantiate and bind (called loading) related Java objects (called beans) according to a given configuration. An XML fi...

Lazy Loading
A bean is loaded only when an instance of that Java class is requested by any other method or a class. org.springframework.beans.factory.BeanFactory (and subclasses) container loads beans lazily. Following code snippet demonstrate lazy loading, concentrate on how "beans.xml" spring configuration file is loaded by BeanFactory container class.
BeanFactory factory =
new XmlBeanFactory(
new InputStreamResource(
new FileInputStream("beans.xml")));// 1
Employee emp = (Employee) factory.getBean("employeeBean");// 2
Pre-loading
All beans are instantiated as soon as the spring configuration is loaded by a container. org.springframework.context.ApplicationContext container follows pre-loading methodology.
ApplicationContext context =
new ClassPathXmlApplicationContext("beans.xml"); 1
Employee emp = (Employee) context.getBean("employeeBean"); // 2
COMMENTS