我们在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引用了hedgingProperties
bean
<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
时,如何保留context:property-placeholder
bean的别名或引用?
答案 0 :(得分: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>