如果说依赖注入式spring框架的核心概念的话,那么applicationContext则是它的核心对象
applicationContext是BeanFactory的特化,后者是由spring管理的所有对象的注册表。
在正常情况下,BeanFactory负责创建bean,将其与任何依赖连接起来,并为bean提供方便的
查找工具。
application可以看作是一个服务齐全的BeanFactory,应用程序通常是与applicationContext
而不是BeanFactory相交互。ApplicationContext比BeanFactory提供了更多的功能,在初始化后,
applicationContext能通过运行BeanFactoryPostProcessors自动处理BeanFactory。
简单的Spring applicationContext.xml如下:
<beans> <bean id="cashRegister" class="org.example.CashRegisterIml"> <property name="priceMatrix" ref="priceMatrixBean" </bean> <bean id="priceMatrixBean" class="org.example.PriceMatrixImpl"> </bean>
上述例子可翻译为以下java代码:
CashRegister cashRegister = new CashRegisterImpl();
PriceMatrix priceMatrixBean = new PriceMatrixImpl();
cashRegister.setPriceMatrix(priceMatrixBean);
本文摘自《深入解析Spring MVC与Web Flow》