Spring - 从属性文件中检索值

标签 spring properties

我的 applicationContext.xml 中有以下配置:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
       <list>
         <value>classpath:app.properties</value>
      </list>
    </property>
</bean>

现在,在我的 java 类中,如何从文件 app.properties 中读取值?

最佳答案

在 Spring 3.0 中,您可以使用 @Value 注释。

@Component
class MyComponent {

  @Value("${valueKey}")
  private String valueFromPropertyFile;
}

关于Spring - 从属性文件中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5592897/

相关文章:

java - Spring 调度程序在服务器上不工作

javascript - 根据属性从对象数组中过滤对象

java - Spring Cloud Dataflow应用程序http返回401未经授权

java - 限制基于 CXF JAX-RS 的服务中的输出有效负载响应

spring - Hibernate 5 与 Spring JTA

spring - 使用 spring 社交推特继续获得 401(需要授权)

ios - Objective-C:如何获取 NSMutableArray 中对象的属性?

javascript - 对象的方法可以将要恢复的对象本身的名称存储为 JavaScript 中的字符串吗?

installation - WiX:如何在外部设置属性?

java - 在Java中模拟 `property` : how to use public field as property?