1. 程式人生 > >Iintellij IDEA配置SpringMVC專案出現的問題

Iintellij IDEA配置SpringMVC專案出現的問題

最近開始學習SpringMVC,想著先搭建一個環境試試手,誰知遇到了莫大的挫折。

首先網上很多教程很詳細,但個人感覺都是自己熟練了之後寫出來的,很多包或者配置都是之前已經寫好的,這就給新手留下了很多問題。

我按照相關教程配置完成之後的第一個問題是Tomcat啟動不起來,找到原因

Artifact MySpring:war exploded: Error during artifact deployment. See server log for details.
解決方法:滑鼠左鍵選中專案->F4->Artifacts,將紅色區域記憶體在的包->右鍵->put into outputRoot。左後右側無包即可。


這僅僅是第一個問題,接著是第二個問題,dispatcher-servlet.xml檔案中 context:component-scan  等標籤不識別

解決辦法:名稱空間有問題,建議引入較為全面的名稱空間

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

就在我以為大功告成時出現第三個問題
 Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
嗯,少了個包,需要手動引入一個jstl包(本人還沒有接觸maven,如果添加了maven就不會這麼多問題了,這個後面討論)。


還沒有結束哦,還需要新增到classes下,依然是選中專案->F4->Libraries->點選左上角+然後選擇剛剛拷貝到lib資料夾下的jstl包新增進去即可,點選下面的Apply,ok.



最後附一張成功的截圖



補充說明:出現的很多問題都是莫名其妙缺少東西,所以建議以後的專案全部用maven,這樣會減少很多問題。