【发布时间】:2015-12-27 04:57:12
【问题描述】:
我想知道:是否可以在 spring applicationContext.xml 中为 PropertyPlaceholderConfigurer 设置属性文件相对于 xml 文件本身的位置?
所以当 applicationContext.xml 和 dataSource.properties 文件在同一个目录下时: 像这样的东西会起作用,还是 Spring 找不到文件,因为我必须修改 location-property 值?
<bean id="dataSourceProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="dataSource.properties" />
</bean>
提前谢谢你!
【问题讨论】:
-
你测试过它并且它有效吗?它应该。
-
现在我做到了 - 它没有:原因:org.springframework.beans.factory.BeanInitializationException:无法加载属性;嵌套异常是 java.io.FileNotFoundException: dataSource.properties (No such file or directory) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89) 所以我想知道如何简单地解决这个问题尽可能:)
标签: java spring spring-mvc properties-file applicationcontext