如何在Spring工厂bean中使用PropertiesOverrideConfigurer?这些是我的bean定义。
<bean id="dataFeedFactory" class="com.gottex.gottware.datafeeds.factories.DataFeedFactory">
<property name="dummyIntervalDistribution" ref="fixedIntervalGenerator"/>
<property name="dummyStep" value="0.0001"/>
<property name="serverAddress" value="${com.gottex.gottware.datafeeds.bloomberg.server.address}"/>
<property name="serverPort" value="${com.gottex.gottware.datafeeds.bloomberg.server.port}"/>
</bean>
<bean id="referenceDataRequester" factory-bean="dataFeedFactory" factory-method="referenceDataRequester">
<constructor-arg name="datasource" value="${com.gottex.gottware.datafeeds.mode}"/>
</bean>
我想用来自另一个属性文件的东西替换constructor-arg“datasource”。我知道如何将SpringOverrideConfigurer用于spring bean,工厂bean的用途是什么?
答案 0 :(得分:0)
替换构造函数arg的正确策略是使用较低顺序的PropertyPlaceholderConfigurer,以便替换属性的现有值,如下所示
<bean id="mainPropertiesConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<props>
<prop key="myProp">mypropvalue</prop>
</props>
</property>
<property name="order" value="100"/>
</bean>
<bean id="overriderPropertiesConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<props>
<prop key="myProp">mypropoverridenvalue</prop>
</props>
</property>
<property name="order" value="1"/>
</bean>