使用 spring3 @Value 访问 PropertyPlaceholderConfigurer 值?

2023-11-26

我正在尝试使用 spring bean 设置字符串的值@Value,当我的财产来源是的子类时PropertyPlaceholderConfigurer。有人知道怎么做吗 ?


老问题,但仍然值得回答。您可以像使用原始表达式一样使用该表达式PropertyPlaceholderConfigurer.

应用程序属性

    app.value=Injected

应用程序上下文.xml

    <bean id="propertyConfigurer" class="MyPropertyPlaceholderConfigurer">
      <property name="location">
        <value>file:app.properties</value>
      </property>
    </bean>

在目标 bean 中

    @Value(value="${app.value}")
    private String injected;

使用 Spring 3.0.6 测试了此方法

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 spring3 @Value 访问 PropertyPlaceholderConfigurer 值? 的相关文章

随机推荐