基于maven从头搭建springMVC框架
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框架的更多相关文章
- 脚手架快速搭建springMVC框架项目
apid-framework脚手架快速搭建springMVC框架项目 rapid-framework介绍: 一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...
- 搭建springmvc框架的另一种思路
在一个完整的项目里搭建springmvc框架的时候, 通常情况下,初学者在配置的时候,总是会把"中央控制器的名字"-servlet.xml文件放到/Webroot/WEB-INF下 ...
- 大师养成计划之一:搭建springmvc框架
搭建spring-mvc框架 搭建spring-mvc框架步骤: 1.搭建web项目spring-mvc1 2.引入jar包 3.配置web.xml 3.1拷贝头文件: <web-app xml ...
- Idea搭建SpringMVC框架(初次接触)
公司转Java开发,做的第一个项目是SpringMVC框架,因为底层是同事封装,等完成整个项目,对SpringMVC框架的搭建还不是很了解,所以抽时间不忙的时候自己搭建了一个SpringMVC框架. ...
- 教你搭建SpringMVC框架( 更新中、附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
- 基于Maven构建整合SpringMVC+Mybtis+Druid
前几天趁空闲时间整合了下SpringMVC+Mybatis+Druid,这里小记录下,这个Demo是基于Maven构建的,数据源用的是阿里巴巴温少的开源项目Druid,数据库用的是Mysql. 由于E ...
- 简单搭建SpringMVC框架详解
在公司待了两年,用的一直是Spring+SpringMVC+Hibernate框架,都是公司自己搭建好的,自己从来没有主动搭建过,闲来无聊,自己搭建试试.一下即我搭建的过程以及搭建所遇到的问题,有部分 ...
- 教你搭建SpringMVC框架( 附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
- Idea使用maven搭建SpringMVC框架
https://www.cnblogs.com/shang-shang/p/7477607.html
随机推荐
- Eclipse中设置JDK、${user}变量
为eclipse设置jdk方法: 两个方法: 1.设置PATH路径-eclipse自动会查找! 2.在快捷方式中加上参数:-VM java虚拟机路径 Eclipse中设置${user}变量 在Ecli ...
- mybatis MySQL返回插入的主键ID,oracle不行
<insertid=“doSomething"parameterType="map"useGeneratedKeys="true"keyProp ...
- 第一章 先把Kubernetes跑起来
1.1 先跑起来 k8s官网已经为大家准备好了一个现成的最小可用系统. https://kubernetes.io/docs/tutorials/kubernetes-basics/ 1.2 创建K ...
- Centos7.4 版本环境下安装Mysql5.7操作记录
Centos7.x版本下针对Mysql的安装和使用多少跟之前的Centos6之前版本有所不同的,废话就不多赘述了,下面介绍下在centos7.x环境里安装mysql5.7的几种方法: 一.yum方式安 ...
- canvas绘制矩形
canvas绘制矩形 方法 fillRect(x, y, width, height) 画一个实心的矩形 clearRect(x, y, width, height) 清除一块儿矩形区域 stroke ...
- R语言可视化学习笔记之添加p-value和显著性标记
R语言可视化学习笔记之添加p-value和显著性标记 http://www.jianshu.com/p/b7274afff14f?from=timeline 上篇文章中提了一下如何通过ggpubr ...
- [OpenCV Qt教程] 如何在内存中压缩图像
本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-comprimere-un-immagine-in-memoria/ ...
- 咱妈说别乱点链接之浅谈CSRF攻击
平时经常听到人们说别乱点链接,小心有病毒.还有长辈们转发的“天呐~XXX的阴谋,全是病毒”.“XXX惊天大病毒,点了苹果手机就要爆炸!”.“现在转发热门连接会乱扣费!千万别点!”. 到底长辈们说的这些 ...
- 获取properties配置
1. 使用@Value @Value("${swagger.enable}") 使用Spring的PropertyPlaceholderConfigurer关联 @Val ...
- BurpSuite系列(十二)----User options模块(用户选择)
一.简介 User options模块主要用来配置一些常用的选项. 二.模块说明 User options主要由4个模块组成: 1.Connections 连接 2.SSL 3.Display 4 ...