gpt4 book ai didi

Spring - 从属性文件中检索值

转载 作者:IT老高 更新时间:2023-10-28 13:58:10 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com