Eclipse利用Maven2搭建SpringMVC框架的Web工程

一、準備工作:

  下載apache-maven--> 配置Maven_home -->下載Eclipse Maven插件

二、新建工程:

   ? 選擇新建Maven Project ?archetype選擇webapp-->輸入group ID (src下包名)和Artifact ID (工程名)

新建Maven工程目錄如上圖

三、補齊缺失的文件夾:

? ? ? ? ? 添加Server支持和缺失的源文件夾

四、添加springMvc支持和web容器支持(若沒有,打包時會報錯)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.maven.my</groupId><artifactId>TestMaven2</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>TestMaven2 Maven Webapp</name><url>http://maven.apache.org</url>

<properties>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>


<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency></dependencies><build><finalName>TestMaven2</finalName></build> </project>

(五)修改工程配置:

?在以上兩個文件中修改jdk版本為1.7以上 web為3.0

六:添加springMvc配置:

web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="study" version="3.0"><display-name>Archetype Created Web Application</display-name><description>sprintMVC環境搭建</description><!-- 加載Spring配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:configs/beans.xml</param-value></context-param><!-- Spring監聽 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Spring MVC配置 --><servlet><servlet-name>Dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 自定義spring mvc的配置文件名稱和路徑 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:configs/beans-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- spring mvc 請求后綴 --><servlet-mapping><servlet-name>Dispatcher</servlet-name><url-pattern>/</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>

src/com/main/resources文件夾下的beans.xml和beans-mvc.xml

beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  xmlns:context="http://www.springframework.org/schema/context"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="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" >  <context:property-placeholder /><context:annotation-config /></beans>    
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:property-placeholder /><!-- MVC控制類掃描 --><context:component-scan base-package="com.my.controller" /><mvc:annotation-driven /><!-- 視圖解析器:定義跳轉的文件的前后綴 -->    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">    <property name="prefix" value="/view/" />    <property name="suffix" value=".html" />  <!--可為空,方便實現自已的依據擴展名來選擇視圖解釋類的邏輯  -->  </bean>    <mvc:default-servlet-handler />    </beans>

七:補齊自己的controller

package com.my.controller;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping("/user")
public class UserController {@RequestMapping(value="/getUserInfo")public String getUserInfo(HttpServletRequest request){System.out.println("==========");return "user";}
}

八:部署運行,輸入http://localhost:8180/TestMaven2/user/getUserInfo訪問。

------------------------------------------------------------------------------------------------------------------------------

一段可能會用到代碼:maven依賴無法加入到工程時,在.classpath添加,很有用

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"><attributes><attribute name="maven.pomderived" value="true"/><attribute name="org.eclipse.jst.component.nondependency" value=""/></attributes></classpathentry>

?

轉載于:https://www.cnblogs.com/liangblog/p/5138415.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/285869.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/285869.shtml
英文地址,請注明出處:http://en.pswp.cn/news/285869.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【ArcGIS風暴】ArcGIS10.6獲取柵格影像邊界范圍的三種方法案例詳解

基于ArcGIS平臺有多種辦法可以提取柵格影像邊界,常見的方法有3種: 柵格范圍(Raster Domain)柵格轉面(Raster to Polygon)創建輪廓(BuildFootprints)/構建邊界(BuildBoundary)文章目錄 1. 柵格范圍(Raster Domain)2. 柵格轉面(Raster to Polygon)3. 創建輪廓(Bui…

七、結構體《2022 solidity8.+ 版本教程到實戰》

結構體 結構體是一種可以自行定義的數據類型&#xff0c;其結構體內是復合的數據類型結構&#xff0c;當單一數據類型不能滿足時可以使用創建所需結構體。 結構體定義使用 struct&#xff0c;例如以下示例&#xff1a; struct Human{uint age;string name;uint height;}以上…

微服務落地,我們在考慮什么?

原創&#xff1a; 李寧 博云技術社區 導讀 微服務已經成為過去幾年軟件架構設計的“事實標準”&#xff0c;大多數企業在推動內部數字化轉型的過程中&#xff0c;服務軟件系統開始由單一或者SOA服務向微服務轉型。那么轉型過程需要遵循哪些原則呢&#xff1f;本文結合過往博云…

IDEA中使用數據庫可視化操作工具

文章目錄 1.入門介紹2. 沒有數據庫驅動3. 準備&測試連接3.1測試報錯 4.連接5.編寫SQL語句 1.入門介紹 在IDEA的專業版的右側工具欄應該會有DataBase按鈕如果沒有的同學可以這樣操作(必須是IDEA專業版) 新建數據庫 2. 沒有數據庫驅動 如果提示: missing driver files ,…

WPF效果第一百九十篇之再耍ListBox

前面一篇效果基于Expander和ListBox實現了一下所需要的效果;今天再次實現點底部不一樣的效果;最終實現的效果:1、ItemContainerStyle我是比較簡單粗暴直接分了二行:ListBoxCanvas實現:<ControlTemplate TargetType"{x:Type ListBoxItem}"><Grid Background&…

C語言試題七十四之請編寫函數求兩個數的最小公倍數

??個人主頁:個人主頁 ??系列專欄:C語言試題200例目錄 ??推薦一款刷算法、筆試、面經、拿大公司offer神器 ?? 點擊跳轉進入網站 ?作者簡介:大家好,我是碼莎拉蒂,CSDN博客專家(全站排名Top 50),阿里云博客專家、51CTO博客專家、華為云享專家 1、題目 編寫函數:…

Rabbitmq~對Vhost的配置

rabbitmq里有一些概念我們要清楚&#xff0c;如vhost,channel,exchange,queue等&#xff0c;而前段時間在部署rabbitmq環境時啟用了虛擬主機vhost&#xff0c;感覺他主要是起到了消息隔離的作用,下面分別再說一下它們的知識。 VHost vhost去做第一層的區分&#xff0c;虛擬主機…

【無人機駕照】無人機駕駛員考試題庫選擇題1060道(帶答案)

001.無人機的英文縮寫是 A. UVS B. UAS C. UAV 答案:C. 002.輕型無人機,是指空機質量 A. 小于7kg B. 大于7kg,小于116kg C. 大于116kg,小于5700kg 答案:B. 003近程無人機活動半徑在 A. 小于15km B. 15~50km C. 200~800km 答案:B. 004任務高度一般在0~100m之間的無人…

表單元素 開篇

今天開始講述表單這個重要模塊 可以說,JS 最早是為表單而發明的, 因此在沒有JS之前,所有操作都需要提交后端驗證,發現有誤再重定向回原頁面, 加上之前1,2KB的網速,這用戶體驗真是奇差無比.因此JS最初發明出來&#xff0c;就是做表單驗證的&#xff0e; 圍繞表單&#xff0c;添加…

目錄(文章更新中...)《實戰NFT web3 solidity(新版本0.8.+)》

注&#xff1a;由于是付費專欄內容&#xff0c;若有錯誤請及時聯系1_bit&#xff0c;博客鏈接&#xff1a;https://blog.csdn.net/A757291228 &#xff0c;或在文章下留言&#xff0c;收到后將會對錯誤進行改正&#xff0c;若是版本更新導致的問題也希望大家對錯誤進行提交&…

如何畫出一張合格的技術架構圖?

阿里妹導讀&#xff1a;技術傳播的價值&#xff0c;不僅僅體現在通過商業化產品和開源項目來縮短我們構建應用的路徑&#xff0c;加速業務的上線速率&#xff0c;也體現在優秀工程師在工作效率提升、產品性能優化和用戶體驗改善等經驗方面的分享&#xff0c;以提高我們的專業能…

.NET 發布和支持計劃介紹

.NET 發布和支持計劃介紹Intro對于 .NET 的發布&#xff0c;大多數童鞋都知道現在每年發布一個版本&#xff0c;針對 .NET 的發布&#xff0c;最近有些更新&#xff0c;Current 版本將改為 STS 版本&#xff0c;所以寫一篇文章介紹一下每年 11 月都會發布新的 .NET 主要版本&am…

C語言試題七十五之請編寫函數求回文數

??個人主頁:個人主頁 ??系列專欄:C語言試題200例目錄 ??推薦一款刷算法、筆試、面經、拿大公司offer神器 ?? 點擊跳轉進入網站 ?作者簡介:大家好,我是碼莎拉蒂,CSDN博客專家(全站排名Top 50),阿里云博客專家、51CTO博客專家、華為云享專家 1、題目 編寫函數:…

【spring boot】8.spring boot的日志框架logback使用

在繼續上一篇的Debug調試之后&#xff0c;把spring boot的日志框架使用情況逐步蠶食。 參考&#xff1a;http://tengj.top/2017/04/05/springbo 開篇之前&#xff0c;貼上完整application.properties日志相關配置 簡介&#xff1a;spring boot的默認日志框架Logback SLF4J——…

【無人機知識】吐血整理:史上最全最完整的飛機基本參數名稱詳解

飛機基本參數大全: 機翼(airfoil):產生飛行所需升力,支持飛機在空中飛行,也有穩定操縱的作用。副翼(aileron):是指安裝在機翼翼梢后緣的一小塊可動的翼面。飛行員操縱左右副翼差動偏轉所產生的滾轉力矩可以使飛機做橫滾機動。機身(fuselage):裝載機組成員、旅客、貨…

通過iscsi配置在aix上掛載存儲設備

本文中我們利用starwind虛擬存儲進行設置&#xff0c;以下為實驗環境說明&#xff1a;Windows環境&#xff1a;win7&#xff0c;ip address:10.3.5.7&#xff0c;iscsi initiator name &#xff1a;iqn.2008-08.com.starwindsoftware:joker-pc-aixAix環境&#xff1a;ip addres…

16進制可逆加密算法

16進制可逆操作類&#xff1a; public static class Hex16{/// <summary>/// 作用&#xff1a;將字符串內容轉化為16進制數據編碼&#xff0c;其逆過程是Decode/// 參數說明&#xff1a;/// strEncode 需要轉化的原始字符串/// 轉換的過程是直接把字符轉換成Unicode字符,…

原生js聲音播放代碼

最終測試頁頁面 測試頁面html代碼(test.html) <!doctype html> <html lang"en"><head><meta charset"UTF-8"><meta name"Generator" content"EditPlus"><meta name"Author" content"…

寫給 Kubernetes 工程師的 mTLS 指南

本文翻譯節選自 A Kubernetes engineer’s guide to mTLS[1]&#xff0c;為了便于讀者理解&#xff0c;筆者對原文做了一點修改 &#xff08;本文刪除了原文中的與主題關系不大的 Linkerd 安裝的部分&#xff0c;將 Twillio 替換成國內讀者比較熟悉的 GitHub&#xff09;。因為…

ArcGIS實驗教程——實驗三十五:ArcGIS Model Builder與空間建模原理、案例詳解

ArcGIS實驗視頻教程合集:《ArcGIS實驗教程從入門到精通》(附配套實驗數據)》 文章目錄 一、 空間建模概述1. 空間建模概述2. 空間建模步驟二、Model Builder建模1. Model Builder基礎2. Model Builder操作3. Model Builder高級進階操作一、 空間建模概述 1. 空間建模概述 …