基于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
随机推荐
- webpack快速入门(一):安装
webpack入门系列,从安装到使用再到放弃....全套的哟,呵呵 首先说明,我是一个后端开发,好几年没碰过前端了,想当年写前端的时候jq还是主流,那时的前端还单纯的像个处女一样,哪有什么构建工具.依 ...
- hadoop从调整GC到关键Counter计算原理分析
hadoop集群中发现使用Parallel Scavenge+Parallel Old收集器组合进行垃圾收集(这也是server端jvm默认的GC方式)时CPU占用可能会非常高,偶尔会出现爆满的状态 ...
- python学习 (三十一) python中的class
1 python的类: Python类都继承自object. __init__: 构造函数,如果不写,有一个默认的. __init__: 这个构造函数只能有一个,Python中不能有多个构造函数. ...
- 关于Eclipse中复制粘贴一个项目后的操作
今天在做一个小Demo,内容和之前的项目有些类似就直接复制过来了,项目名修改了,web.xml的项目名也修改了,可是部署到Tomcat之后,以这个新项目名进行访问就会出现404的错误,只可以使用复制之 ...
- 5月9日上课笔记-网页定位、网页动画【HTML5】
一.网页定位 position: static (默认值) relative 相对定位(相对原来的位置) right left botton top absolute 绝对定位 fixed: 固定定位 ...
- RefWorks
RefWorks公司简介/RefWorks 编辑 RefWorks是美国剑桥信息集团的子公司,是ProQuest 的姊妹公司.该公司于2001年由参考文献管理领域的一些专家组建而成,并致力于为学术机构 ...
- 第六章 声明式服务调用: Spring Cloud Feign
我们在使用 Spring Cloud Ribbon 时, 通常都会利用它对 RestTemplate 的请求拦截来实现对依赖服务的接口调用, 而 RestTemplate 已经实现了对 HTTP 请求 ...
- 21_java之File对象和递归遍历
01IO技术概述 * A:IO技术概述 * a: Output * 把内存中的数据存储到持久化设备上这个动作称为输出(写)Output操作 * b: Input * 把持久设备上的数据读取到内存中的这 ...
- jquery 实现点击图片居住放大缩小
该功能是基于jquery实现的,所以 第一步则是引入jquery jquery下载地址:https://jquery.com/download/ 或者使用此时调试的版本(3版本) /*! jQuery ...
- K老在拿图灵奖时的发言:Computer Programming as an Art
很多话说得很透彻,把一些觉比较精彩的摘抄一下. ... It seems to me that if the authors I studied were writing today, they wo ...