Java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

Source: Internet
Author: User
Tags addchild tomcat server

When building a Web project using the spring framework, we need to configure a spring context listener in XML:

  1   < initialize a applicationcontext in the context domain when the server starts!-----  2   <listener>   3     <listener-class>org.springframework.web.context.contextloaderlistener</ listener-class>  4   </listener>
XML Code

Then the console console error java.lang.classnotfoundexception:o after starting the Tomcat server Rg.springframework.web.context.ContextLoaderListener.

Exception Description:

1Severity: Error Configuring Application Listener ofclassOrg.springframework.web.context.ContextLoaderListener2Java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener3At Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1858)4At Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1701)5At Org.apache.catalina.core.DefaultInstanceManager.loadClass (defaultinstancemanager.java:504)6At Org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged (defaultinstancemanager.java:486)7At Org.apache.catalina.core.DefaultInstanceManager.newInstance (defaultinstancemanager.java:113)8At Org.apache.catalina.core.StandardContext.listenerStart (standardcontext.java:4984)9At Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5584)TenAt Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:147) OneAt Org.apache.catalina.core.ContainerBase.addChildInternal (containerbase.java:899) AAt Org.apache.catalina.core.ContainerBase.addChild (containerbase.java:875) -At Org.apache.catalina.core.StandardHost.addChild (standardhost.java:652) -At Org.apache.catalina.startup.HostConfig.deployDirectory (hostconfig.java:1260) theAt Org.apache.catalina.startup.hostconfig$deploydirectory.run (hostconfig.java:2002) -At Java.util.concurrent.executors$runnableadapter.call (executors.java:511) -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) + 
Error Code

Error Analysis:

The wrong meaning is clear: "Org.springframework.web.context.ContextLoaderListener" is not found in the class, Contextloaderlistener This class is under the Spring-web.jar package, carefully examined the project JAR environment, found in the Web project Lib import in the Spring jar package, is indeed missing the import of a named Spring-web-4.3.8.release.jar's jar package. Then import and restart the Tomcat server to successfully pass.

Supplementary questions:

If the project jar environment is checked, it is found that the jar package does exist and the compiled Contextloaderlistener.class file can be found. However, the console console still has an error after starting the Tomcat server Java.lang.classnotfoundexception:o Rg.springframework.web.context.ContextLoaderListener.

The problem may be that you are importing only a jar package reference, such as a jar package (like a shortcut) directly referenced in Eclipse's build path, without copying the jar file to the Lib directory. Even if this is not a problem in Java application, exceptions to the class cannot be found in Web application.

We know that the JVM virtual machine is based on the Java ClassLoader (ClassLoader) that determines how the class is loaded. The system provides 3 ClassLoader by default. Root ClassLoader, ClassPath Loader and Ext ClassLoader.

The Web application uses a custom ClassLoader instead of the three classloader that exist in the JVM. So it doesn't recognize the class file of the third-party class library We wrote in the XML file, and only the Java file that we wrote in the SRC directory can be used.

Therefore, we have to put the required third-party class libraries into the Web-inf/lib directory, and the Web application will recognize the classes we define in XML. Then reboot the Tomcat server to get through.

Java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

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.