您的位置:首页 > 编程语言 > Java开发

Spring中读取properties文件的几种方式

2018-03-15 15:59 387 查看
原文:https://www.cnblogs.com/hafiz/p/5876243.html

归纳:

<context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true"/>
示例:
@Value("#{name}")
private String name;


<bean id="prop" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<!-- 这里是PropertiesFactoryBean类,它也有个locations属性,也是接收一个数组,跟上面一样 -->
<property name="locations">
<array>
<value>classpath:config.properties</value>
</array>
</property>
</bean>
示例:
@Value("#{prop.name}")
private String name;


<util:properties id="propertiesReader" location="classpath:config.properties"/>
这种方式创建了一个bean,以bean的方式来使用,示例:
​​​​​​​@Value("#{propertiesReader[name]}")
private String name;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring properties