spring - 使用 spring3 @Value 访问 PropertyPlaceholderConfigurer 值?

标签 spring spring-el

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

最佳答案

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

app.properties

    app.value=Injected

app-context.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 测试了这种方法

关于spring - 使用 spring3 @Value 访问 PropertyPlaceholderConfigurer 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1741968/

相关文章:

spring - @EmbeddedKafka 试图多次注册 AppInfo mbean?

java - 简单的 Spring EL 表达式不起作用;出现错误 TypeMismatchException

java - 使用@PATCH 方法进行 Spring REST 部分更新

spring - Spring中 "context"是什么意思?

java - Spring MVC : Testing particular annotated method gets invoked

Thymeleaf 聚合不起作用

java - Spring - SpEL 将实体参数评估为@PreAuthorize ("hasPermission"中的空引用)

java - 我可以直接从 SpEL 表达式创建 bean 吗?

java - Spring - 在 xml 中获取系统环境变量会导致空指针异常

spring - @NamedQuery 覆盖 Spring Data Rest JpaRepository 中的 findAll