Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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配置位置文件异常_Spring_Spring Security - Fatal编程技术网

未找到Spring配置位置文件异常

未找到Spring配置位置文件异常,spring,spring-security,Spring,Spring Security,在我的web应用程序中,我尝试使用spring security。我有以下项目结构: 在my web.xml中,我将配置位置设置为: 在HibernateUtil中,我创建了ClassPathXmlApplicationContext,如下所示: 但是,当我执行应用程序时,会出现以下错误: GRAVE: Exception sending context initialized event to listener instance of class org.springframewo

在我的web应用程序中,我尝试使用spring security。我有以下项目结构:

在my web.xml中,我将配置位置设置为:

在HibernateUtil中,我创建了ClassPathXmlApplicationContext,如下所示:

但是,当我执行应用程序时,会出现以下错误:

GRAVE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML    document from class path resource [resources/applicationContext.xml]; nested exception is    java.io.FileNotFoundException: class path resource [resources/applicationContext.xml] cannot     be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.io.FileNotFoundException: class path resource [resources/applicationContext.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 20 more
可能有什么问题?

请参阅maven war插件

检查目标文件夹是否实际包含这些文件


错误清楚地告诉您,它在类路径中找不到resources/applicationContext.xml

查看您的代码组织,我认为问题在于您的Spring应用程序onContext.xml文件直接位于WEB-INF下,在典型的WEB应用程序中,这是类路径中的而不是。您最好创建一个WEB-INF/classes/文件夹,并将applicationContext.xml文件放在其中


由于错误是关于resources/appliationContext.xml的,因此您可能还需要创建一个WEB-INF/classes/resources/文件夹并将其放入其中。

您是否已检查该文件是否已打包到WAR中?如果它不在类路径上,您将得到错误。您可能需要使用maven war插件的构建设置。我将标记添加到pom.xml中,这就解决了问题。是的,我想这就是原因,但我想让您看看文档。如果下次你能自己找到的话,这样做更好:)我考虑过不投这个票,因为这个答案的语气。告诉某人反应“清晰”可见是居高临下。如果他们清楚,他们不会寻求帮助。