xml – 使用spring覆盖属性文件
发布时间:2020-12-16 07:59:03 所属栏目:百科 来源:网络整理
导读:我在我的一个Spring(3.1)XML中定义了以下属性文件: context:property-placeholder location="classpath:MyConfigFile.properties"/ 我希望能够定义第二个可选属性文件,该文件将覆盖“MyConfigFile.properties”文件并将被加载而不是它. 换句话说,我希望我的
我在我的一个Spring(3.1)XML中定义了以下属性文件:
<context:property-placeholder location="classpath:MyConfigFile.properties"/> 我希望能够定义第二个可选属性文件,该文件将覆盖“MyConfigFile.properties”文件并将被加载而不是它. 换句话说,我希望我的应用程序加载“MyConfigFile.properties”文件,但如果在类路径中有“StrogerConfigFile.properties”,它将被加载. 任何人都知道如何使用Spring XML完成它? <context:property-placeholder location="file:///[path]/override1.properties,file:///[path]/override2.properties" properties-ref="defaultProps" /> <bean id="defaultProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <array> <value>classpath:default1.properties</value> <value>classpath:default2.properties</value> </array> </property> <property name="properties"> <util:properties local-override="true"> <prop key="some.property">some value</prop> </util:properties> </property> </bean> 这是我使用的设置非常灵活.允许您直接在xml中使用基本默认值,在属性文件中使用默认值,并在另一个属性文件中覆盖. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |