【发布时间】:2015-07-03 06:43:07
【问题描述】:
我尝试实现一个自己的PropertyPlaceholderConfigurer,它在构造函数中使用另一个PropertyPlaceholderConfigurer 的属性。我试着这样做。
<!-- load properties which are used in second configurer -->
<context:property-placeholder
location="classpath:config.properties" ignore-unresolvable="true" order="1" />
<bean class="com.example.MyPropertyPlaceholderConfigurer">
<!-- use property of other file -->
<constructor-arg value="${password}" />
<property name="location">
<value>file:config.properties</value>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
config.properties
password=1234
但是MyPropertyPlaceholderConfigurer的构造函数中的属性${password}没有解析。
我的错误是什么?
【问题讨论】:
-
我不知道为什么有些火鸡把你记下来了:(。问:你提到“conf.properties”;你的代码有“config.properties”和“config2.properties”。有吗真的是三个不同的文件?还是拼写错误?
-
我的错误。我在问题中拼错了。但是文件在那里。我在其他位置使用第一个占位符的属性,它们在那里得到解决。
-
那行不通(正如您已经经历过的那样)。使用属性占位符不是一个多步骤过程,它们都是
BeanFactoryPostProcessors 并且在生命周期的早期运行,它们不会相互操作。唯一可行的占位符替换是基于系统属性。 -
好的。非常感谢您的澄清。 PropertyOverrideConfigurer 也是这种情况吗? (我也尝试过这种方法,但没有运气)