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.mzph.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. 空间建模概述 …