我收到以下錯誤消息,當我嘗試啓動彈簧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>
'WEB-INF \ classes'是WAR文件中的正確位置。 'classpath:file.properties'是指示文件將位於此處的正確方法。我只能建議Eclipse可能構建的WAR與預期不同。它是否適用於獨立的Tomcat? – 2012-04-12 21:51:31