【发布时间】:2012-04-25 06:50:49
【问题描述】:
我在尝试启动 Spring Web 应用程序时收到以下错误消息:
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 一起使用吗?
标签: spring filenotfoundexception properties-file timex