动态弹簧属性

时间:2011-07-06 09:28:42

标签: spring spring-mvc

大家好,有没有动态更改spring属性文件内容的好例子?如果你能给我一些例子或链接,我将非常感激。

非常感谢

2 个答案:

答案 0 :(得分:5)

我认为您可以使用ReloadableResourceBundleMessageSource。它使用java.util.Properties个实例作为邮件的内部数据结构。

此外,顾名思义,此类支持通过cacheSeconds设置重新加载属性文件,还可以通过编程方式清除属性缓存。请注意,由于应用程序服务器通常会缓存从类路径加载的所有文件,因此您必须将属性文件放在类路径之外(WEB-INF/classes),否则它将被缓存并且不起作用。


参考/示例/链接

答案 1 :(得分:-2)

实际上,spring支持配置文件中的$ {variable},如下所示

<bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>               
<value>file:${XXX}/XXX.properties</value>
<value>file:${XXX}/YYY.properties</value>
</list>
</property>
</bean>