1

我们在 spring 上下文中有这个现有的属性加载器配置

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <util:list>
            <value>hedging-service.properties</value>
        </util:list>
    </property>
</bean>

<!--Hedging properties bean that can be injected into other beans-->
<util:properties id="hedgingProperties" location="classpath:hedging-service.properties"/>

并且有一个引用该bean 的hedgingPropertiesbean

<bean id="mailProcessor"
    class="a.b.c.MailProcessor">
    <property name="properties" ref="hedgingProperties"/>
    ...
</bean>

我正在重构上下文以从多个属性文件加载,并避免属性的重复定义。我的第一次尝试是用这个bean代替上面的两个

<context:property-placeholder location="classpath:hedging-service-core.properties,classpath:hedging-service.properties,classpath:icon.properties"/>

hedgingProperties但是当我使用 bean 时如何保留别名或引用context:property-placeholder

4

1 回答 1

0

答案是混合context:property-placeholderutil:properties

<util:properties id="hedgingProperties" location="classpath:hedging-service.properties"/>
<context:property-placeholder properties-ref="hedgingProperties" />

<bean id="mailProcessor" class="a.b.c.MailProcessor">
    <property name="properties" ref="hedgingProperties"/>
    ...
</bean>
于 2014-03-24T14:24:15.740 回答