Java. Lang. classnotfoundexception: org. springframework. Web. Context. contextloaderservlet

Source: Internet
Author: User

Check whether there is any exception: Java. Lang. classnotfoundexception: org. springframework. Web. Context. contextloaderservlet

Therefore, contextloaderservlet is not loaded successfully, leading to failure in building spring containers in Web. xml! Therefore, when you reference webapplicationcontextutils, java. Lang. noclassdeffounderror: ORG/springframework/web/Context/support/webapplicationcontextutils appears.

Scenario 1: webapplicationcontext wctx = webapplicationcontextutils. getrequiredwebapplicationcontext (servletcontext );

My spring-web.jsr package has been added, why can't the webapplicationcontextutils class be found while the program is running?

In one tutorial, I don't understand what it means: "An application context is obtained during action initialization. Reuse spring's webapplicationcontextutils class. If there is no available context, this action will not be correctly initialized ".

Case 2: (most of them are here and we are hit! Haha)

Your project packages may all be referenced. You need to manually copy them to the project!

Case 3:

The Spring framework has its own internal ing mechanism. The main problem is that the corresponding ing bean reference is not found!

<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> COM/wenjing/hibernate/test/wenjing-servlet.xml </param-value>
</Context-param>
This paragraph for a try, can be written to the spring-servlet.xml reference
The content is as follows:
Bean id = "newbaseaction" class = "DB. pbaseaction">
<Property name = "View"> <value> newbaseaction </value> </property>
</Bean>
Case 4:

You are using hibernate3.0! But not in your spring configuration file

<Bean id = "sessionfactory" class = "org. springframework. Orm. hibernate. localsessionfactorybean">

It should be:
<Bean id = "sessionfactory" class = "org. springframework. Orm. hibernate3.localsessionfactorybean">

Try it!

Case 5:

Keywords: Spring and Web Application Integration Method details

1. Copy the jar package of spring to the WEB-INF/lib directory of the Web application.

2. modify web. xml so that the application server can automatically load spring beanfactory objects.

<Context-param>

<Param-Name> contextconfiglocation </param-Name>

<Param-value>/WEB-INF/applicationcontext-*. XML, classpath *: applicationcontext-*. xml </param-value>

</Context-param>

<Listener>

<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>

</Listener>

3. You can use the webapplicationcontextutils tool class in Web components.

An instance that obtains the beanfactory object. It owns the beanfactory object.

The container management capability of spring.

Explanation:

The result of this configuration is that spring uses contextloaderlistener to set the webapplicationcontext object

(Beanfactory subclass) put in servletcontext and get the value named a static variable:

Webapplicationcontext. root_web_application_context_attribute

* The webapplicationcontextutils. getapplicationcontext () method is used to obtain the webapplicationcontext.

Object Value

* You can also use request. getsession (). getservletcontext (). getattribute (webapplicationcontext. root_web_applicat

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.