java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderServlet伺服器啟動報異常

來源:互聯網
上載者:User

標籤:java.lang.classnotfo   java.lang.org.spring   contextloaderservlet   伺服器啟動異常   spring項目啟動異常   

今天配置的Tomcat伺服器,啟動springMVC項目,報java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderServlet異常,還有異常:java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderServlet等異常,解決問題網上查了很多資料,特意總結如下:

 

情況1:

WebApplicationContext wctx=WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 
我的spring-web.jsr的包已經加上了,為什麼程式運行時,找不到WebApplicationContextUtils類呢? 
有一個教程上說了這樣的一句話,我不理解是什麼意思“在Action初始化時獲得一個應用程式上下文。重用spring的WebApplicationContextUtils類,如果沒有可用的上下文,該動作不會正確的初始化”。

 

情況2:

你的工程包有可能都是引用的,需要把它們都手動拷貝到工程中來!

 

情況3:

spring架構有自已內在一套映射機制,樓主的問題是由於沒有找到相應的映射BEAN引用而產生! 
<context-param> 
<param-name>contextconfiglocation</param-name> 
<param-value>com/wenjing/hibernate/test/wenjing-servlet.xml</param-value> 
</context-param> 
這一段換一種方式試一試,可以寫到spring-servlet.xml當中引用 
內容如下 :

 

 

<bean id="newBaseAction" class="db.PBaseAction"> <property name="view"><value>newBaseAction</value></property> </bean>   


情況4:

 

你用的是hibernate3.0吧! 但你的spring設定檔中不是 
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> 
應該是: 
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
你試試!

 

情況5:

關鍵字: Spring與Web應用整合的方法細講

1、將spring的相關jar包,拷貝到web應用的WEB-INF/lib目錄下 
2、修改web.xml,讓應用伺服器自動載入spring的BeanFactory對象 

<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、在web組件裡,可以使用WebApplicationContextUtils工具類來 獲得BeanFactory對象的執行個體,擁有了BeanFactory對象,就擁有 了spring的容器管理的能力。 
解釋: 
   這種配置的結果是,spring通過ContextLoaderListener將WebApplicationContext對象 
   (BeanFactory的子類)放入ServletContext中,並取名為一個靜態變數的值: 
   WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE 
   * 通過WebApplicationContextUtils.getApplicationContext()方法就可以獲得WebApplicationContext
對象的值 
* 或者通過request.getSession().getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICAT

 

 

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderServlet伺服器啟動報異常

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.