尝试启动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文件夹中并使用classpath:/timex-servlet.properties(请注意classpath之后的斜杠:)

关于spring - java.io.FileNotFoundException:类路径资源[timex-servlet.properties]无法打开,因为它不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10131812/

10-12 19:49