利用Spring的ApplicationContext加载Property文件,可以实现国际化和'热'加载文件(不用重启应用).Spring提供了ResourceBundleMessageSource和ReloadableResourceBundleMessageSource两个类加载property文件,后者提供了'热'加载以及指定编码等功能.
例子:配置文件
<!--
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames"> <list> <value>resource/msg1</value>
<value>resource/msg2</value> </list> </property> </bean>
-->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="gbk" />
<property name="cacheSeconds" value="5" />
<property name="basenames">