【发布时间】:2012-01-23 10:53:21
【问题描述】:
我想在 spring 3 应用程序中使用 <util:properties> 标签加载多个属性文件。
我在博客上搜索过,但找不到正确的路径。
希望有人能给我解决这个问题的答案。
【问题讨论】:
标签: spring spring-mvc
我想在 spring 3 应用程序中使用 <util:properties> 标签加载多个属性文件。
我在博客上搜索过,但找不到正确的路径。
希望有人能给我解决这个问题的答案。
【问题讨论】:
标签: spring spring-mvc
实际上<util:properties> 只是org.springframework.beans.factory.config.PropertiesFactoryBean 的方便标记。而PropertiesFactoryBean 确实支持多个位置。
因此可以通过这种方式使用Properties 创建bean:
<bean id="myProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:myprops-common.properties</value>
<value>classpath:myprops-override.properties</value>
<value>classpath:some-more-props-here.properties</value>
</list>
</property>
</bean>
【讨论】:
我的解决方案
<context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
【讨论】:
util:properties 似乎只支持 1 个属性文件 (reference)。您可能想要使用@peperg 建议的配置。
【讨论】: