Spring Tutorial Step by Step
Introduction to BeanFactory
The BeanFactory interface is the central IoC container interface in Spring. Its responsibilities include instantiating or sourcing application objects, configuring such objects, and assembling the dependencies between these objects.
Instantiating a Spring IoC container
Resource resource = new FileSystemResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
... or...
ClassPathResource resource = new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
... or...
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
// ApplicationContext is just a BeanFactory
BeanFactory factory = context;
// get EmpBean object
EmpBean empbean = factory.getBean("empbean");
|