春找不到的src /主/資源在我的屬性文件(MyPropFile.properties)春找不到的src/main /資源的內部屬性文件並拋出類似的異常以下Maven項目:使用PropertyPlaceholderConfigurer
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 /資源內部文件
這是我的命名空間
<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;
在此先感謝你們。
我已經更新了我的問題,反映了你建議的先生的更改 不幸的是,它仍然無法找到屬性文件 java.io.FileNotFoundException:MyPropFile.properties(系統找不到文件指定) – royjavelosa
註釋'PropertyPlaceholderConfigurer'的bean定義並嘗試構建並運行你的應用程序 –
只有當MyPropFile.properties位於我的項目的根目錄下時,它纔會工作我希望它可以工作,即使它在src/main/resources/MyPropFile.properties – royjavelosa