在spring中,ApplicationContext 作为BeanFactory接口的派生,不仅具有了BeanFactory的所有功能,还提供了以下功能。(BeanFactory主要负责Bean的初始化,配置和管理)
1。messageSource 国际化消息的访问
2。资源访问 如URL和文件
3。事件传播 如实现了ApplicationListener的接口
4。加载多个上下文,每个上下文负责特定的层次,比如应用的web层
下面,我们来看一下国际化消息的访问,话不多说,直接看代码。
首先是在applicationContext.xml中的配置:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>local.message</value>
<value>local/sex</value>
</list>
</property>
</bean>
其次是资源文件的位置以及message.properties的配置信息