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