0.准备工作

首先将eclipse和需要的插件准备好,例如maven插件,spring IDE插件。

1.建立maven下的webapp项目

  1.新建一个maven项目,类型为webapp,如下图

  2.然后给项目命名,加入groupId等

  3.配置项目的发布目录,在 Deployment Assemly下,如图

2.配置Spring和Maven

  1.配置pom.xml,添加如下包依赖。版本不一定要对应,后边可能会用到些新的包,缺少哪些包可以后续去百度然后加入到pom.xml中

     <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

  2.配置web.xml文件,添加ContextLoaderListener监听器,在servlet启动时会去装配制定配置文件的配置;然后添加springDispatcherServlet,指定mvc配置文件,配置mvc框架。全部配置如下:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context.xml,
/WEB-INF/spring-hibernate.xml
</param-value>
</context-param> <!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- 设置监听位置,'/'为全部监听 -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

  3.配置spring-mvc.xml

<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <!-- 激活@controller模式 -->
<mvc:annotation-driven />
<!-- 配置包扫描位置(会在此包下扫描@controller控制器) -->
<context:component-scan base-package="com.test.maven.controller" />
<!-- 配置视图解析器(jsp文件前缀后缀) -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- 配置tiles模板(没有用到tiles可以不用配置此项) -->
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-definitions.xml</value>
</list>
</property> </bean> </beans>

  4.配置spring-context.xml。暂时只建立最简单的框架,所以这里暂时可以不用配置。

到此最基本的springMVC框架就搭建好了。把项目装入tomcat,运行访问项目的主目录,就会调用默认的index.jsp,显示hello world了。

基于maven从头搭建springMVC框架的更多相关文章

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

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

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

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

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

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

  4. Idea搭建SpringMVC框架(初次接触)

    公司转Java开发,做的第一个项目是SpringMVC框架,因为底层是同事封装,等完成整个项目,对SpringMVC框架的搭建还不是很了解,所以抽时间不忙的时候自己搭建了一个SpringMVC框架. ...

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

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

  6. 基于Maven构建整合SpringMVC+Mybtis+Druid

    前几天趁空闲时间整合了下SpringMVC+Mybatis+Druid,这里小记录下,这个Demo是基于Maven构建的,数据源用的是阿里巴巴温少的开源项目Druid,数据库用的是Mysql. 由于E ...

  7. 简单搭建SpringMVC框架详解

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

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

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

  9. Idea使用maven搭建SpringMVC框架

    https://www.cnblogs.com/shang-shang/p/7477607.html

随机推荐

  1. 使用wifi网卡笔记1----网卡选型、开发环境搭建、内核配置

    1.wifi的STA模式和AP模式 Ap(Access Point)模式指的是可以将网卡设置为路由器用来共享流量或有线网络给别人使用, sta模式指的是当做网卡连接路由器上网 (1):AP也就是无线接 ...

  2. 【UVa】208 Firetruck(dfs)

    题目 题目     分析 一开始不信lrj的话,没判联通,果然T了. 没必要全部跑一遍判,只需要判断一下有没有点与n联通,邻接表不太好判,但无向图可以转换成去判n与什么联通. 关于为什么要判,还是因为 ...

  3. JAVA中的IO流介绍(2)

    一.流的概念 流(stream)的概念源于UNIX中管道(pipe)的概念.在UNIX中,管道是一条不间断的字节流,用来实现程序或进程间的通信,或读写外围设备.外部文件等. 一个流,必有源端和目的端, ...

  4. python打造XslGenerator

    0x00前言 今天加载了Demon哥分享的RSS.其中有一篇是三好学生讲的: 在仔细越读这篇文章后,我懂得了里面的一些骚操作,所以有了以下的 脚本. 0x001代码 import optparse i ...

  5. Nginx配置ProxyCache缓存

    利用nginx cache缓存网站数据 nginx本身就有缓存功能,能够缓存静态对象,比如图片.CSS.JS等内容直接缓存到本地,下次访问相同对象时,直接从缓存即可,无需访问后端静态服务器以及存储存储 ...

  6. pycharm git工具与coding.net结合

    前提:coding.net中的项目是私密项目 问题描述:在使用pycharm自带的git工具clone(或者push)代码时出现 错误如下:Push failed: Failed with error ...

  7. halcon采集一幅图像

    **顺序也很重要,必须现有窗口,才能设置属性 dev_close_window()dev_open_window (0, 0, 1400, 1200, 'black', WindowHandle)de ...

  8. 教你用一行Python代码实现并行(转)

    教你用一行Python代码实现并行 本文教你通过一行Python实现并行化. Python在程序并行化方面多少有些声名狼藉.撇开技术上的问题,例如线程的实现和GIL,我觉得错误的教学指导才是主要问题. ...

  9. FilreDAC DLL共享数据连接

    D:\Users\Public\Documents\Embarcadero\Studio\16.0\Samples\Object Pascal\Database\FireDAC\Samples\Com ...

  10. Programming Entity Framework-dbContext 学习笔记第五章

    ### Programming Entity Framework-dbContext 学习笔记 第五章 将图表添加到Context中的方式及容易出现的错误 方法 结果 警告 Add Root 图标中的 ...