2012-04-12 82 views
2

我收到以下錯誤消息,當我嘗試啓動彈簧Web應用程序:java.io.FileNotFoundException:類路徑的資源[timex-servlet.properties]不能打開,因爲它不存在

2012-04-12 13:53:20,491 ERROR [org.springframework.web.servlet.DispatcherServlet] - 

Context initialization failed 
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [timex-servlet.properties] cannot be opened because it does not exist 
java.io.FileNotFoundException: class path resource [timex-servlet.properties] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137) 
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:172) 

我正在通過eclipse運行Tomcat(版本6.x)。我試圖把timex-servlet.properties在以下目錄中,但無濟於事:

WebContent\WEB-INF 
WebContent\WEB-INF\classes 
WebContent\ 

這裏是參考的Timex-servlet.xml中timex-servlet.properties:

<bean id="placeholderConfig" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" 
     value="timex-servlet.properties" /> 
</bean> 

有幾個SO線程處理相同的消息,說放置類路徑:在屬性文件引用的前面。所以我嘗試以下,這也沒有工作:

 <bean id="placeholderConfig" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" 
     value="classpath:timex-servlet.properties" /> 
</bean> 
+2

'WEB-INF \ classes'是WAR文件中的正確位置。 'classpath:file.properties'是指示文件將位於此處的正確方法。我只能建議Eclipse可能構建的WAR與預期不同。它是否適用於獨立的Tomcat? – 2012-04-12 21:51:31

回答

13

確保文件被放置在/WEB-INF/classes文件夾並使用classpath:/timex-servlet.properties(注意類路徑:)後斜線

3

如果你不想動它在課下,想離開WEB-INF下的屬性文件/請嘗試以下內容 classpath:../ file.properties

0

對於Spring項目,將文件放在src或src-> somefolder-> some下。屬性文件。

相關問題