【SpringMVC學習筆記】03 使用maven建立springMVC專案
阿新 • • 發佈:2019-02-06
6.建立controller
7.建立home.jsp8.配置預設主頁面右鍵-run as
9.配置JDK外掛預設情況下eclipse的maven專案使用jdk1.5編譯,需要新增maven的jdk編譯外掛 定義變數:非必須
10.也可以用maven的tomcat外掛執行maven專案(1)加入外掛
(2)執行專案配置name:起名字隨意Goals:tomcatX:run 大小寫嚴格區分
外掛執行:
在web.xml依賴注入時會報錯。Caused by: org.apache.catalina.LifecycleException: A child container failed during start
原因:網速慢,下載jar包出錯,可以用maventest檢測jar包是否安裝成功,也可去maven的本地倉庫檢視是否有如下格式的檔案,為未下載成功解決方案:刪除jar包資料夾下所有檔案,重新maven install下載新jar包
@ControllerpublicclassIndexController {/** * 主頁設定 "/"的話預設情況下就訪問 * @return */@RequestMapping("/")public String home() {return"home"; }} |
<welcome-file-list> <welcome-file>/</welcome-file> </welcome-file-list> |
<properties><!-- 定義變數 <encoding>${project.build.sourceEncoding}改為UTF-8</encoding>--><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
<build><plugins><!-- java編譯外掛 --><!-- 解決每次更新maven專案,用於編譯maven專案的jdk會變回1.5 --><plugin> |
<!-- 配置Tomcat外掛 多個專案多個tomcat --><!-- 本地可以不安裝tomcat和本地tomcat無關 --><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><!-- tomcat版本 --><configuration><port>8001</port><!-- 自定義埠號 --><path>/springmvc</path><!-- 專案的路徑 --></configuration></plugin> |
外掛執行:
在web.xml依賴注入時會報錯。Caused by: org.apache.catalina.LifecycleException: A child container failed during start
原因:網速慢,下載jar包出錯,可以用maventest檢測jar包是否安裝成功,也可去maven的本地倉庫檢視是否有如下格式的檔案,為未下載成功解決方案:刪除jar包資料夾下所有檔案,重新maven install下載新jar包