使用Spring PropertyPlaceholderConfigurer注入错误的值

时间:2014-11-04 19:50:51

标签: java spring

我有两个属性文件:

prop1.properties:
prop1.sample=value123

prop2.properties:
prop2.sample=value234

当我将这些属性值注入两个我的" InjectValues"豆然后一切都以适当的方式运作。但是当我想从一个PropertyPlaceHolder注入一个值到另一个只是扩展PropertyPlaceHolder而不是value的类时,键将被插入,如下所示。

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>file:C:\test\prop1.properties</value>
    </property>
    <property name="placeholderPrefix" value="${" />
    <property name="placeholderSuffix" value="}" />
</bean>

<bean id="propertyConfigurerNew"
    class="com.test.spring.property.EncryptedPlaceHolder">
    <property name="location">
        <value>file:C:\test\prop2.properties</value>
    </property>
    <property name="key" value="${prop1.sample}" /> <!-- Value "${prop1.sample}" is injected instead of value123 -->
    <property name="placeholderPrefix" value="#[" />
    <property name="placeholderSuffix" value="]" />
</bean>

<bean id="injectValues"
    class="com.test.spring.property.InjectValues">
    <property name="value1" value="${prop1.sample}" /> <!-- Correct value "value123" is injected -->
    <property name="value2" value="#[prop2.sample]" /> <!-- Correct value "value234" is injected -->
</bean>

1 个答案:

答案 0 :(得分:0)

看起来PropertyPlaceHolders不能替换其他PropertyPlaceHolders中的占位符,因为它们是在注释中提到的相同阶段执行的。