【发布时间】:2013-10-21 21:42:18
【问题描述】:
Spring 在 src/main/resources 中找不到我的属性文件 (MyPropFile.properties) 并引发如下异常
java.io.FileNotFoundException: class path resource [file*:/src/main/resources/MyPropFile.properties] cannot be opened because it does not exist
但是如果我将 MyPropFile.properties 放在我的项目的根目录(MyProject/MyPropFile.properties),spring 可以找到它并且程序可以正常执行。
如何配置它以便我可以将 .properties 文件放在 src/main/resources 中
这是我的命名空间
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
这是我的豆子
<context:property-placeholder location="classpath:MyPropFile.properties" />
Java:
@Value("${message.fromfile}")
private String message;
提前谢谢各位。
【问题讨论】: