Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml [英] Spring Mvc java.io.FileNotFoundException - ApplicationContext.xml

查看:131
本文介绍了Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

applicationContext.xml位于WEB-INF文件夹中,为什么出现此错误:

The applicationContext.xml is in the WEB-INF folder, why am i getting this error :

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="crimeTrack" version="3.0">

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
         <param-name>log4jConfigLocation</param-name> 
         <param-value>/WEB-INF/classes/log4j.properties</param-value>
     </context-param>

     <listener>
          <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
     </listener>

     <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener> 

    <servlet>
        <servlet-name>crimetrack</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>crimetrack</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>
      index.jsp
    </welcome-file>
    </welcome-file-list>

    <jsp-config>
        <taglib>
            <taglib-uri>/spring</taglib-uri>
            <taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
        </taglib>
    </jsp-config>

</web-app>

推荐答案

我必须坚持使用 WEB-INF 文件中的/resources 目录,否则您可以给它起任何你想要的名字. 类路径查看 WEB-INF 目录,但它会扫描该目录中的文件夹.我将 applicationContext.xml servlet.xml 文件移到了 WEB-INF/resources 目录中,因此可以将其从 WEB-INF 的根目录,无需维护 applicationContext.xml servlet.xml 文件的两个副本.

i had to stick to using the /resources directory in the WEB-INF file or you can name it anything you want. The classpath looks at the WEB-INF directory however it scans the folders within that directory. I moved the applicationContext.xml and the servlet.xml files into the WEB-INF/resources directory, so yes it can be deleted from the root of the WEB-INF and there is no need to maintain two copies of an applicationContext.xml or servlet.xml files.

这篇关于Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆