我的 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/