1. 程式人生 > >使用eclipse啟動tomcat裏的項目時報錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

使用eclipse啟動tomcat裏的項目時報錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

data 選中 ins 應用 可能 sem 電腦系統 cep 彈出

1、這種錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener剛開始看的時候一頭霧水,說找不到類,而且是springframework包裏面的。

技術分享圖片

但這應該是絕不可能發生的事,因為我這個項目SSMTest是好久以前就搭建的一個項目,是專門搭建後方便用來測試一些其他技術的,這個SSMTest項目已經用了很久了配置什麽的肯定是沒有問題的,今天電腦系統出了點問題,然後在eclipse中不能復制和粘貼,我把eclipse的配置重置了一遍,重新導入了SSMTest項目,重新配置了tomcat,然後把SSMTest項目add到tomcat裏,啟動tomcat。

居然給了報了一個java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener的錯誤,導致項目沒有啟動成功,開始我還以為是加載spring的包出了問題,又是build 項目,然後又是clean 清理tomcat工作目錄的操作,然並沒有什麽卵用。

2、解決辦法:

  好吧,百度了一下,在其他博客上看到了問題所在,親測也確實就這樣解決了,借鑒博客地址:https://adminjun.iteye.com/blog/2249323

  2.1、java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener這個問題到底是什麽問題呢?

    看他的博客說是因為工程部署後,進入到進入到tomcat的部署路徑.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\目錄下,檢查在WEB-INF目錄下沒有生成lib目錄,所以導致啟動項目失敗。

  解決方案:

    

    1.右鍵點擊項目--選擇Properties

    選擇Deployment Assembly,在右邊點擊Add按鈕,在彈出的窗口中選擇Java Build Path Entries

    2.點擊Next,選擇Maven Dependencies

    3.點擊Finish,然後可以看到已經把Maven Dependencies添加到Web應用結構中了

    操作完後,重新部署工程

操作流程圖:(1、選中項目右鍵,選擇properties。2、選擇Deployment Assembly。3、點擊add,選擇Java Build Path Entries,保存、保存、保存,然後重新部署就ok了)

  技術分享圖片

技術分享圖片

使用eclipse啟動tomcat裏的項目時報錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener