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>

複数のプロパティ ファイルからロードするようにコンテキストをリファクタリングし、プロパティの定義が重複しないようにしています。私の最初の試みは、上記の2つの代わりにこの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-placeholderであり、util: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 に答える