一、准备工作:

  下载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.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://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>

Eclipse利用Maven2搭建SpringMVC框架的Web工程的更多相关文章

  1. 教你搭建SpringMVC框架( 更新中、附源码)

    一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...

  2. 脚手架快速搭建springMVC框架项目

    apid-framework脚手架快速搭建springMVC框架项目   rapid-framework介绍:   一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...

  3. 教你搭建SpringMVC框架( 附源码)

    一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...

  4. 大师养成计划之一:搭建springmvc框架

    搭建spring-mvc框架 搭建spring-mvc框架步骤: 1.搭建web项目spring-mvc1 2.引入jar包 3.配置web.xml 3.1拷贝头文件: <web-app xml ...

  5. 搭建springmvc框架的另一种思路

    在一个完整的项目里搭建springmvc框架的时候, 通常情况下,初学者在配置的时候,总是会把"中央控制器的名字"-servlet.xml文件放到/Webroot/WEB-INF下 ...

  6. 利用 nodeJS 搭建一个简单的Web服务器(转)

    下面的代码演示如何利用 nodeJS 搭建一个简单的Web服务器: 1. 文件 WebServer.js: //-------------------------------------------- ...

  7. 使用eclipse创建在myeclipse中运行的web工程

    今天在跟随慕课网学习java时,遇到课程中老师使用Myeclipse,我用的是eclipse,那么就使用eclipse创建在Myeclipse项目 参考: 如何在Eclipse配置Tomcat服务器 ...

  8. SpringMVC框架下Web项目的搭建与部署

    这篇文章已被废弃. 现在,Deolin使用Maven构建项目,而不是下载Jar文件,使用Jetty插件调试项目,而不是外部启动Tomcat. SpringMVC比起Servlet/JSP方便了太多 W ...

  9. 简单搭建SpringMVC框架详解

    在公司待了两年,用的一直是Spring+SpringMVC+Hibernate框架,都是公司自己搭建好的,自己从来没有主动搭建过,闲来无聊,自己搭建试试.一下即我搭建的过程以及搭建所遇到的问题,有部分 ...

随机推荐

  1. 烂泥:学习ubuntu远程桌面(一):配置远程桌面

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 公司服务器目前安装的都是ubuntu 14.04系统,而且由于业务需要,需要使用到ubuntu的远程桌面功能.所以本篇文章都是围绕ubuntu的远程桌面来 ...

  2. 烂泥:rsync与inotify集成实现数据实时同步更新

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 上篇文章我们介绍了如何使用rsync同步文件,这篇文章我们再来介绍下,如何把rsync与inotify集成实现数据的实时同步. 要达到这个目的,我们需要 ...

  3. eclipse设置显示代码行数(转)

    (转自:http://jingyan.baidu.com/article/b2c186c89b7023c46ef6ff27.html) 载入eclipse的主页面,默认以英文版的eclipse为例 点 ...

  4. Apache

    一.简介 Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速.可靠并且可通过简单的A ...

  5. VS设置程序集属性(文件的详细信息)

    适用范围 本文方法适用于:C#创建的控制台程序,WinForm,WPF等VS创建的.Net工程信息设置. 方法步骤 1.在 项目 上点击鼠标右键选择 属性 ,进入这个页面,点击 程序集信息(重点关注 ...

  6. 用jsmooth + inno生成exe并制作简单安装包

    思路: 先由 Jsmooth把jar和相关资源打包生成exe,再由Inno把exe和资源文件打成安装包 一  Jsmooth 1 下载 安装 Jsmooth   地址:jsmooth.sourcefo ...

  7. java 22 - 19 多线程之生产者和消费者的代码优化

    在之前,是把生产者录入数据和消费者获取数据的所有代码都分别写在各自的类中. 这样不大好 这次把生产者和消费者部分关键代码都写入资源类中: package zl_Thread; public class ...

  8. 用nodejs搭建一个简单的服务器

    使用nodejs搭建一个简单的服务器 nodejs优点:性能高(读写文件) 数据操作能力强 官网:www.nodejs.org 验证是否安装成功:cmd命令行中输入node -v 如果显示版本号表示安 ...

  9. DINIC网络流+当前弧优化

    DINIC网络流+当前弧优化 const inf=; type rec=record s,e,w,next:longint; end; var b,bb,d,q,tb:..] of longint; ...

  10. javascript中的双向队列

    1.概念 我们知道队列是一种先进先出的结构,只能在队伍的开头添加元素,队伍的结尾删除元素.双向队列的概念就是同时允许在队伍的开头和结尾添加和删除元素.在javascript中有一个处理数组的方法Arr ...