Java. lang. ClassNotFoundException: org. springframework. web. context. ContextLoaderL, spring Get context

Source: Internet
Author: User

Java. lang. ClassNotFoundException: org. springframework. web. context. ContextLoaderL, spring Get context

The following error message is displayed when I learned about the spring Project today:

Java. lang. ClassNotFoundException: org. springframework. web. context. ContextLoaderListener
At org. apache. catalina. loader. WebappClassLoader. loadClass (WebappClassLoader. java: 1702)
At org. apache. catalina. loader. WebappClassLoader. loadClass (WebappClassLoader. java: 1547)
At org. apache. catalina. core. DefaultInstanceManager. loadClass (defainstinstancemanager. java: 532)
At org. apache. catalina. core. DefaultInstanceManager. loadClassMaybePrivileged (defainstinstancemanager. java: 514)
At org. apache. catalina. core. DefaultInstanceManager. newInstance (defainstinstancemanager. java: 142)
At org. apache. catalina. core. StandardContext. listenerStart (StandardContext. java: 4854)
At org. apache. catalina. core. StandardContext. startInternal (StandardContext. java: 5434)
At org. apache. catalina. util. LifecycleBase. start (LifecycleBase. java: 150)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1559)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1549)
At java. util. concurrent. FutureTask $ Sync. innerRun (FutureTask. java: 334)
At java. util. concurrent. FutureTask. run (FutureTask. java: 166)
At java. util. concurrent. ThreadPoolExecutor. runWorker (ThreadPoolExecutor. java: 1145)
At java. util. concurrent. ThreadPoolExecutor $ Worker. run (ThreadPoolExecutor. java: 615)
At java. lang. Thread. run (Thread. java: 722)

Although this is the case at a Glance: java. lang. ClassNotFoundException: org. springframework. web. context. ContextLoaderListener


But it is still a bit confused, because the previous practice spring, is to copy the jar package to the WEB-INF/Lib directory, but recently the practice project is to build their own different User libaraies, obviously, I have already imported these jar packages, but it prompts such information ..............

It seems that I am introducing the third-party jar package mechanism that we need for JVM. Then I searched the following on the Internet to understand the principle. The following is not a nonsense and I will focus on it directly:

  1. The Java ClassLoader (Class Loader) determines how to load the Class.
  2. By default, the system provides three ClassLoader
  3. Root ClassLoader, ClassPath Loader, Ext ClassLoader
  4. You can also write your own ClassLoader to load Jar files in a specific environment.
  5. Whether the Jar can be loaded or where the Jar is loaded is determined by ClassLoader.
  6. The main problem may be that only jar package references are imported, for example, adding user lib in eclipse through build path ...... (Similar to shortcuts)
  7. This is okay in Java Application, but exceptions that cannot be found in web Application may occur.
  8. In WEB Application, it is best to place the jar package in the lib folder under webroot or webcontent, especially the jar package used in xml.

It turns out that when we use Ant-like methods to retrieve classes, we cannot use them like UserLibaray, because we create a web app, while a web app uses a custom ClassLoader, instead of the three ClassLoader existing in the JVM (as mentioned above), it cannot identify the class file of the third-party class library written in the xml file, only java files written in the src directory can be used. Therefore, we must put third-party class libraries under the lib directory, the web app will recognize the classes we define in xml.

This error also makes my understanding of classloader a step. although I have read Zhou Zhiming's in-depth introduction to the Class Loader Distribution System in JVM, I don't quite understand it. As a result, I also have some experience.


JavalangClassNotFoundException: orgspringframeworkwebcontextContextLoa

The jar package of spring-web is not imported.
Jar package conflict, delete repeated jar packages
In the web. add <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: applicationContext -*. xml </param-value> </context-param>
Because the default read is/WEB-INF under the configuration file, if the configuration file in src to change the path to under the class path
4. Refresh the project. Because the project is deployed under the server, you need to deploy the added jar package to the project.

 
Startup error: javalangClassNotFoundException: orgspringframeworkwebcontextContextLoaderListener

The jar package is not imported, but also buildpath, that is, the Creation Path. In Myeclipse, right-click your jar package and click build path -- "add build path. Complete the Creation Path. In addition, there is not only one jar package in spring, but the most basic is three.



 

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.