PropertyPlaceholderConfigurer
We use PropertyPlaceholderConfigurer
when we need to load some property files whose properties are used in applicationcontext.xml of spring. We can use the properties directly using JSTL expressions.
ReloadableResourceBundleMessageSource
We use ReloadableResourceBundleMessageSource
when we need to use the property files outside the applicationcontext.xml. The properties loaded using ReloadableResourceBundleMessageSource are not accessible in applicationcontext.xml
在Spring 中可以使用以下两个类加载资源文件:org.springframework.context.support.ResourceBundleMessageSource和org.springframework.context.support.ReloadableResourceBundleMessageSource
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>com.examples.bundle.aa</value>
<value>com.examples.bundle.bb</value>
</list>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>com.examples.bundle.aa</value>
<value>com.examples.bundle.bb</value>
</list>
</property>
</bean>
其中:aa和bb 分别com.examples.bundle下的aa.properties和aa.properties 文件
区别:ReloadableResourceBundleMessageSource可以不重起服务器的情况下,读取资源文件,所以可以随时更改资源文件