首页 > 代码库 > nested exception is java.io.FileNotFoundException: Could not open ServletContext resource

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource

  1. <context-param>  
  2.     <param-name>contextConfigLocation</param-name>  
  3.     <param-value>classpath:applicationContext.xml</param-value>  
  4. </context-param>  

 

注意这段配置尽量写在靠前的位置,因为在tomcat启动后web项目会先初始化上下文,我们这段配置正是指定了上下文配置的文件位置,在上下文初始化完成之后才应当继续加载其余各种配置,而我们的springMVC的servlet仅仅是springMVC框架的相关配置,就好比struts2的配置一样,项目整体还是由spring去管理的。

 

学习自:http://blog.csdn.net/wlwlwlwl015/article/details/48134763

报错信息:

月 10, 2017 9:31:12 下午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 二月 10, 2017 9:31:13 下午 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:344)  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)  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:129)  at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  at java.lang.Thread.run(Thread.java:745) Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]  at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)  ... 21 more

二月 10, 2017 9:31:13 下午 org.apache.catalina.core.StandardContext startInternal 严重: One or more listeners failed to start. Full details will be found in the appropriate container log file 二月 10, 2017 9:31:13 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom 信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [179] milliseconds. 二月 10, 2017 9:31:13 下午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/SpringUnit01] startup failed due to previous errors 二月 10, 2017 9:31:13 下午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 二月 10, 2017 9:31:13 下午 org.apache.catalina.core.StandardContext listenerStop 严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalStateException: BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the ApplicationContext  at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)  at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:908)  at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:884)  at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836)  at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)  at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)  at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4859)  at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)  at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:224)

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource