Maven搭建SSM框架(SpringMVC+Spring+Mybatis)
Maven搭建SSM框架(SpringMVC+Spring+Mybatis)
简介
本文章提供了详细的搭建过程,供大家参考学习。
案例Demo已托管至Github,详情查看SSM Demo
另附上本人基于SSM搭建的高效便捷开发框架,上手就能用:
- 单节点项目:详情参考使用Maven构建 基于SpringMVC+Spring+Mybatis(SSM)高效便捷开发框架
- 分布式项目:详情参考使用Maven构建 整合Dubbo+Zookeeper+SpringMVC+Spring+MyBatis支持分布式 高效便捷开发框架
环境
- MacOS Sierra / Windows 7
- MySql 5.7
- JDK 1.8
- Eclipse 4.6.1
- Maven 3.3.9
- Jetty 9.4.6.v20170531 / Tomcat 9.0
技术选型
名称 | 描述 | 版本号 | 网址 |
---|---|---|---|
Spring MVC | MVC框架 | 4.3.10.RELEASE | https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc |
Spring Framework | 容器 | 4.3.10.RELEASE | http://projects.spring.io/spring-framework/ |
MyBatis | ORM/持久层框架 | 3.4.5 | http://www.mybatis.org/mybatis-3/zh/index.html |
AspectJ | 面向切面的框架 | 1.8.10 | http://www.eclipse.org/aspectj/ |
Druid | 数据库连接池 | 1.1.3 | https://github.com/alibaba/druid |
Jackson | json解析器 | 2.9.1 | https://github.com/FasterXML/jackson |
Logback | 日志组件 | 1.2.3 | https://logback.qos.ch |
Maven | 项目构建管理 | 3.3.9 | http://maven.apache.org/ |
搭建步骤
一、创建Maven项目
具体操作如下图
新建好的项目会有报错提示,别着急,在项目上右键选择 Java EE Tools > Generate Deployment Descriptor Stub
接下来在项目上右键选择最后一项 Properties > Project Facets
到这里一个Maven的Web项目就创建好了
二、在pom.xml中添加依赖包
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.frame</groupId>
<artifactId>ssm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.framework.version>4.3.11.RELEASE</spring.framework.version>
<aspectj.version>1.8.10</aspectj.version>
<jackson.version>2.9.1</jackson.version>
<logback.version>1.2.3</logback.version>
</properties>
<dependencies>
<!-- 添加 commons 依赖包 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<!-- 添加 spring 依赖包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<!-- 添加 aspectJ 依赖包 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- 添加 mybatis 依赖包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring