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

时间:2012-11-06 00:50:30

标签: spring spring-security

在我的网络应用程序中,我正在尝试使用Spring安全性。我有以下项目结构:

Project structure http://i48.tinypic.com/17q1zq.png

在我的web.xml中,我设置了这样的configLocations:

Project structure http://i45.tinypic.com/smpvmw.png

在我的HibernateUtil中,我创建了这样的ClassPathXmlApplicationContext:

Project structure http://i49.tinypic.com/ev1jxv.png

但是,当我执行应用程序时,我收到以下错误:

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

可能出现什么问题?

2 个答案:

答案 0 :(得分:2)

请参阅maven war插件。

检查目标文件夹实际上是否包含文件。

https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

答案 1 :(得分:0)

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

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

由于错误是抱怨资源/ appliationContext.xml,您可能还需要创建一个WEB-INF / classes / resources /文件夹并将其放在那里。