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

解决Spring配置文件无法读取properties属性问题

2015-09-26 20:30 881 查看
在Spring项目的配置文件中引用properties属性文件中的属性,运行时无法识别properties属性文件中的属性引用,但properties属性文件和属性明明已经存在,例如:





要在Spring中使用外部properties属性文件,需要在Spring配置文件中添加bean后处理器PropertyPlaceholderConfigurer,并指明外部properties属性文件的路径:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="properties路径"/>
</bean>


如果有多个properties属性文件,可以使用下面方式:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>properties路径</value>
<value>properties路径</value>
...
</list>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息