The BeanFactory and ApplicationContext is the actual container which instantiates, configures, and manages a number of beans.
A BeanFactory comes by the interface org.springframework.beans.factory.BeanFactory, for which
there are multiple implementations
ApplicationContext comes in spring j2ee modules i.e spring 2.5
Activating spring beanFactory container is not but creating object for class that implements “org.springframework.beans.factory.BeanFactory” interface.
ApplicationContexts are a subclass of BeanFactory, and most users end up using XML variants of
ApplicationContext).
There are three way to instantiate beanFactory
1 2 | Resource res = new FileSystemResource("beans.xml"); XmlBeanFactory factory = new XmlBeanFactory(res); |
Or
1 2 | ClassPathResource res = new ClassPathResource("beans.xml"); XmlBeanFactory factory = new XmlBeanFactory(res); |
Or
1 2 3 4 | ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml", "applicationContext-part2.xml"}); // of course, an ApplicationContext is just a BeanFactory BeanFactory factory = (BeanFactory) appContext; |