当前位置: 代码迷 >> Web前端 >> [/WEB-INF/applicationContext.xml]解决办法
  详细解决方案

[/WEB-INF/applicationContext.xml]解决办法

热度:2667   发布时间:2012-10-11 10:16:10.0
[/WEB-INF/applicationContext.xml]解决方法

Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]解决方法
问题表现
[Spring]:?ERROR 2009-04-10 21:57:00,093 ContextLoader:initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from?ServletContext?resource?[/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
?at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
?at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
?at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
?at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
?at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
?at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
?at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
?at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
?at org.apache.catalina.core.StandardService.start(StandardService.java:516)
?at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
?at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
?at java.lang.reflect.Method.invoke(Unknown Source)
?at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
?at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
?... 27 more
ERROR 2009-04-10 21:57:00,093 ContextLoader:initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from?ServletContext?resource?[/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
?at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
?at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
?at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
?at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
?at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
?at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
?at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
?at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
?at org.apache.catalina.core.StandardService.start(StandardService.java:516)
?at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
?at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
?at java.lang.reflect.Method.invoke(Unknown Source)
?at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
?at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
?... 27 more
2009-4-10 21:57:00 org.apache.catalina.core.StandardContext listenerStart
严重: 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?ServletContext?resource?[/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
?at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
?at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
?at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
?at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
?at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
?at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
?at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
?at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
?at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
?at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
?at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
?at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
?at org.apache.catalina.core.StandardService.start(StandardService.java:516)
?at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
?at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
?at java.lang.reflect.Method.invoke(Unknown Source)
?at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
?at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.FileNotFoundException:?Could?not?open?ServletContext?resource?[/WEB-INF/applicationContext.xml]
?at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)
?at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
?... 27 more
2009-4-10 21:57:00 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2009-4-10 21:57:00 org.apache.catalina.core.StandardContext start
严重: Context [/auction] startup failed due to previous errors
2009-4-10 21:57:00 org.apache.catalina.core.ApplicationContext?log

解决方法:

在web.xml中加入这些配置

<context-param>
????<param-name>contextConfigLocation?</param-name>
????<param-value>/WEB-INF/classes/applicationContext.xml </param-value>
</context-param>

问题主要由于加载spring的默认配置文件位置一般是在/WEB-INF/下找applicationContext.xml文件。而Myeclipse文件自动生成的applicationContext文件是放在/WEB-INF/classes/applicationContext.xml。所以在默认加载中是找不到applicationContext.xml文件的,必须加入上面配置。

  相关解决方案