spring - java.io.FileNotFoundException : class path resource [timex-servlet. 属性]无法打开,因为它不存在

标签 spring filenotfoundexception properties-file timex

当我尝试启动 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 : class path resource [timex-servlet. 属性]无法打开,因为它不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10131812/

相关文章:

java - Android - java.io.FileNotFoundException 打开失败 : ENOENT (No such file or directory)

c# - 文件存在时找不到 VirtualFileResult 文件

java.io.FileNotFoundException : . 。 (没有这样的文件或目录)

grails - 如何在 grails 3.1.8 中从外部文件加载数据源配置?

java - JDBC Template异常表或 View 不存在但实际存在

java - 由于响应内容类型无效,其余模板交换失败

properties-file - Augeas:如何缩短树路径?

java - Maven TestNG 项目,用 Maven 命令行参数替换属性文件中的值

java - 跨 Java Web 应用程序引用 HTML 页面上的变量

java - 使用不在 JpaRepository 中的 @Query 注释