Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml_Java_Xml_Spring Mvc_Java Io_Applicationcontext - Fatal编程技术网

Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml

Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml,java,xml,spring-mvc,java-io,applicationcontext,Java,Xml,Spring Mvc,Java Io,Applicationcontext,applicationContext.xml位于WEB-INF文件夹中,为什么会出现此错误: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: clas

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

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>

org.springframework.web.context.ContextLoaderListener
log4jConfigLocation
/WEB-INF/classes/log4j.properties
org.springframework.web.util.Log4jConfigListener
org.springframework.web.context.ContextLoaderListener
深渊
org.springframework.web.servlet.DispatcherServlet
1.
深渊
*.htm
index.jsp
/弹簧
/WEB-INF/tld/spring-form.tld

我不得不坚持使用WEB-INF文件中的/resources目录,或者你可以随意命名它。类路径查看WEB-INF目录,但它扫描该目录中的文件夹。我将applicationContext.xmlservlet.xml文件移动到WEB-INF/resources目录中,因此,是的,它可以从WEB-INF的根目录中删除,并且不需要维护applicationContext.xmlservlet.xml文件的两个副本。

在我的情况下,我所需要做的就是从

src\main\webapp\WEB-INF\


src\main\resources\

您需要做的是将ApplicationContext.xml文件添加到源目录中。 然后加载spring配置文件,但不包含任何这样的路径

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");

它会起作用的

你能发布你的web.xml吗?您的异常是spring在类路径中而不是在WEB-INF文件夹中查找WEB.xml看起来很好。您的WEB-INF文件夹中也有crimetrack-servlet.xml吗?是的,它在同一个目录中,我只是将它复制到目录更高的一个名为\resources的文件夹中,该文件夹位于WEB-INF\resources中,并且工作正常。为什么?applicationContext.xml位于WEB-INF的根目录下。我想我需要对此进行解释。将其保留在\resources文件夹中并从WEB-INF的根目录中删除可以吗?我是否应该将crimetrack-servlet.xml文件也移动到\resources目录中