Spring多属性PlaceHolderConfigure(在多个项目中)如何覆盖已定义的属性?
我遇到的情况是,我需要在另一个项目中覆盖一个项目中的属性。在项目1中,我无法控制源代码或配置,有以下配置:Spring多属性PlaceHolderConfigure(在多个项目中)如何覆盖已定义的属性?,spring,Spring,我遇到的情况是,我需要在另一个项目中覆盖一个项目中的属性。在项目1中,我无法控制源代码或配置,有以下配置: <bean id="propSource1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:/sample-properties/prop1.prop
<bean id="propSource1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/sample-properties/prop1.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="-10"/>
</bean>
在我正在处理的另一个项目中,我有以下配置:
<bean id="propSource2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/sample-properties/prop2.properties</value>
<value>classpath:/sample-properties/prop3.properties</value>
</list>
</property>
<property name="order" value="1000"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
classpath:/sample properties/prop2.properties
类路径:/sample properties/prop3.properties
单独而言,这两种配置各自都可以正常工作。当我想用prop2.properties或prop3.properties中的某个属性覆盖prop1.properties中相同属性的值时,就会出现问题。它始终使用prop1.properties中的值。我做了很多研究,但没有发现任何有用的东西
欢迎提出任何建议。答案在@M.Deninum的评论中 您不能通过这种方式重写属性以使重写工作,或者使用带有
@PropertySource
注释的类,或者自己将它们加载到环境中。您必须使用一个较新的组件PropertySourcesPropertyPlaceHolder
。我还建议使用
标记,而不是直接使用类。