【发布时间】:2016-07-01 16:33:37
【问题描述】:
我想通过 XML 配置将 java.util.Properties 对象注入另一个 bean。我尝试了here 列出的解决方案,但没有成功,大概是因为在属性解析发生之前注入了 bean。有没有办法可以强制 java.util.Properties 对象在注入到我的班级之前解析?
以下是我所拥有的修剪/编辑版本。 PropertiesConsumingClass 确实收到了 a、b 和 c 属性文件的合并但未解析的属性。
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="allProperties" />
</bean>
<bean id="allProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="propertiesArray">
<util:list>
<util:properties location="classpath:a.properties" />
<util:properties location="classpath:b.properties" />
<util:properties location="classpath:c.properties" />
</util:list>
</property>
</bean>
<bean class="PropertiesConsumingClass">
<constructor-arg index="0" ref="allProperties" />
</bean>
【问题讨论】: