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 ( Org.apache.catalina.loader.WebappClassLoaderBase.loadClass ( Org.apache.catalina.core.DefaultInstanceManager.loadClass ( Org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged ( Org.apache.catalina.core.DefaultInstanceManager.newInstance ( Org.apache.catalina.core.StandardContext.listenerStart ( Org.apache.catalina.core.StandardContext.startInternal ( Org.apache.catalina.util.LifecycleBase.start ( OneAt Org.apache.catalina.core.ContainerBase.addChildInternal ( AAt Org.apache.catalina.core.ContainerBase.addChild ( -At Org.apache.catalina.core.StandardHost.addChild ( -At Org.apache.catalina.startup.HostConfig.deployDirectory ( theAt Org.apache.catalina.startup.hostconfig$ ( -At Java.util.concurrent.executors$ ( -At ( -At Java.util.concurrent.ThreadPoolExecutor.runWorker ( +At Java.util.concurrent.threadpoolexecutor$ ( -At ( + 
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.


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: 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.