2

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>
4

3 回答 3

2

就我而言,我需要做的就是 applicationContext.xml

src\main\webapp\WEB-INF\

src\main\resources\.

于 2015-01-20T00:17:54.583 回答
1

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

于 2012-09-25T04:11:40.040 回答
0

您需要做的就是将ApplicationContext.xml文件添加到您的源目录中。然后加载没有任何路径的spring配置文件。

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

它会工作的!

于 2019-08-29T00:38:25.987 回答