About the "Could not open ServletContext resource [/web-inf/applicationcontext.xml]" solution

Source: Internet
Author: User
Tags addchild

Problem description, I configured the following in the Web. xml file

<servlet>    <servlet-name>dispatcherServlet</servlet-name>    <servlet-class >org.springframework.web.servlet.dispatcherservlet</servlet-class>    <init-param>      <param-name>contextConfigLocation</param-name>      <param-value>classpath:spring.xml </param-value>    </init-param>    <load-on-startup>ten</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>dispatcherservlet</ servlet-name>    <url-pattern>/*</url-pattern>  </servlet-mapping> 

But the error.

 A-jul- .  +: A:49.829critical [RMI TCP Connection (3)-127.0.0.1] Org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed Org.springframework.beans.factory.BeanDefinitionStoreException:IOException parsing XML Document fromServletContext resource [/web-inf/applicationcontext.xml]; Nested exception isJava.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: the) 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:612) at Org.springframework.context.support.AbstractApplicationContext.refresh (Abstractapplicationcontext.java: 513) at Org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext ( Contextloader.java:444) at Org.springframework.web.context.ContextLoader.initWebApplicationContext (Contextloader.java:326) at org.springframework.web.context.ContextLoaderListener.contextInitialized (Contextloaderlistener.java: 107) at Org.apache.catalina.core.StandardContext.listenerStart (Standardcontext.java:4853) at Org.apache.catalina.core.StandardContext.startInternal (Standardcontext.java:5314) at Org.apache.catalina.util.LifecycleBase.start (Lifecyclebase.java:145) at Org.apache.catalina.core.ContainerBase.addChildInternal (Containerbase.java:753) at Org.apache.catalina.core.ContainerBase.addChild (Containerbase.java:729) at Org.apache.catalina.core.StandardHost.addChild (Standardhost.java:717) at org.apache.catalina.startup.HostConfig.manageApp (Hostconfig.java:1696) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java: +) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java: +) at Java.lang.reflect.Method.invoke (Method.java:498) at Org.apache.tomcat.util.modeler.BaseModelMBean.invoke (Basemodelmbean.java: -) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke (Defaultmbeanserverinterceptor.java:819) at Com.sun.jmx.mbeanserver.JmxMBeanServer.invoke (Jmxmbeanserver.java:801) at Org.apache.catalina.mbeans.MBeanFactory.createStandardContext (Mbeanfactory.java:484) at Org.apache.catalina.mbeans.MBeanFactory.createStandardContext (Mbeanfactory.java:433) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java: +) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java: +) at Java.lang.reflect.Method.invoke (Method.java:498) at Org.apache.tomcat.util.modeler.BaseModelMBean.invoke (Basemodelmbean.java: -) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke (Defaultmbeanserverinterceptor.java:819) at Com.sun.jmx.mbeanserver.JmxMBeanServer.invoke (Jmxmbeanserver.java:801) at Javax.management.remote.rmi.RMIConnectionImpl.doOperation (Rmiconnectionimpl.java:1468) at javax.management.remote.rmi.rmiconnectionimpl.access$ -(Rmiconnectionimpl.java: the) at Javax.management.remote.rmi.rmiconnectionimpl$privilegedoperation.run (Rmiconnectionimpl.java:1309) at Javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation (Rmiconnectionimpl.java:1401) at Javax.management.remote.rmi.RMIConnectionImpl.invoke (Rmiconnectionimpl.java:829) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java: +) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java: +) at Java.lang.reflect.Method.invoke (Method.java:498) at Sun.rmi.server.UnicastServerRef.dispatch (Unicastserverref.java:346) at sun.rmi.transport.transport$1. Run (Transport.java: $) at sun.rmi.transport.transport$1. Run (Transport.java:197) at java.security.AccessController.doPrivileged (Native Method) at Sun.rmi.transport.Transport.serviceCall (Tran Sport.java:196) at Sun.rmi.transport.tcp.TCPTransport.handleMessages (Tcptransport.java:568) at Sun.rmi.transport.tcp.tcptransport$connectionhandler.run0 (Tcptransport.java:826) at sun.rmi.transport.tcp.tcptransport$connectionhandler.lambda$run$0(Tcptransport.java:683) at java.security.AccessController.doPrivileged (Native Method) at Sun.rmi.transport.tcp.tcptransport$connectio Nhandler.run (Tcptransport.java:682) 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: the)    ...  $More

Note that, in fact, the focus is a word, that is, could not open ServletContext resource [/web-inf/applicationcontext.xml], the anomaly is also very obvious, filenotexception, Unable to open ServletContext resource file.

Let's start with the official search for clues and take a look at spring's official documentation, which can be found in the chapters of the Web:

If the <context-parameter> element named Contextconfigloction is not deliberately specified, then spring's Contextloderlistener listener is/web-inf/ Go down and look for and load this file named Applicationcontext.xml under this directory.

So it should be specified in the Web. xml file

<! DOCTYPE web-app Public"-//sun Microsystems, INC.//DTD Web application 2.3//en"        "HTTP://JAVA.SUN.COM/DTD/WEB-APP_2_3.DTD"><web-app> <display-name>archetype Created Web application</display-name> <context-param > <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</ param-value> </context-param> <filter> <filter-name>characterencodingfilter</filter-name > <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <!--resolve form put requests-<filter> <filter-name&gt ;httpputformcontentfilter</filter-name> <filter-class>org.springframework.web.filter.httpputformcontentfilter</filter-class> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <ser Vlet-name>dispatcherservlet</servlet-name> </filter-mapping> <filter-mapping> < Filter-name>httpputformcontentfilter</filter-name> <servlet-name>dispatcherservlet</ servlet-name> </filter-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpa Th:spring.xml</param-value> </init-param> <load-on-startup>Ten</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherservlet</ Servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping></web-app>

Works correctly after modification

About the "Could not open ServletContext resource [/web-inf/applicationcontext.xml]" solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.