Bean Factory
- Bean instantiation/wiring
Application Context
- Bean instantiation/wiring
- Automatic BeanPostProcessor registration
- Automatic BeanFactoryPostProcessor registration
- Convenient MessageSource access (for i18n)
- ApplicationEvent publication
Bean Factory
BeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
reader.loadBeanDefinitions(new ClassPathResource("spring.xml"));
ComponentClass cc = (ComponentClass) beanFactory.getBean("compclass");
<bean id="compclass" class="com.classes.ComponentClass" />
Application Context
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
ComponentClass cc = (ComponentClass) context.getBean("compclass");
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="myproperties.properties" />
<bean id="compclass" class="com.classes.ComponentClass" p:age="${myp.age}" />
<bean id="compclass" class="com.classes.ComponentClass">
<property name="age" value="30"/>
</bean>
Ref:
- http://stackoverflow.com/questions/243385/beanfactory-vs-applicationcontext
- http://stackoverflow.com/questions/5231371/springs-xmlbeanfactory-is-deprecated