【发布时间】:2012-09-25 00:55:38
【问题描述】:
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>
【问题讨论】:
-
你能发布你的 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 目录中
标签: java xml spring-mvc java-io applicationcontext