Spring Mvc java.io.FileNotFoundException-ApplicationContext.xml [英] 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屋!