我的 war 文件之外有一个属性文件,系统管理员使用该文件来关闭某些系统功能。它在我的本地计算机上运行得很好,但是当我们部署到开发环境时,属性文件未上传,应用程序无法启动。我想知道是否有一种方法可以在我的 applicationContext 中为通常来自属性文件的值声明默认值。
我目前用它来读取属性文件:
<util:properties id="myProperties" location="file:${catalina.home}/webapps/myProperties.properties"/>
只要我们记得将属性文件放在正确的位置,就可以正常工作。有没有办法声明默认值,或者如果找不到该文件,则可以从不同的文件中读取?
Thanks
而不是使用<util:properties>
use a 属性FactoryBean http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/config/PropertiesFactoryBean.html with setIgnoreResourceNotFound=true
.
例如:
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound"><value>true</value></property>
<property name="locations">
<list>
<value>classpath:default.properties</value>
<value>file:${catalina.home}/webapps/myProperties.properties</value>
</list>
</property>
</bean>
请注意,列出的文件的顺序很重要。后面文件中的属性将覆盖前面的文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)