本文示例在如下环境下搭建一个Maven+Druid+SSM+Shiro+Mysql+PageHelper以及Mybatis Generator反向生成代码的项目
附上GitHub地址:https://github.com/lujuhao/ssm.git
一.开发环境:
系统:Windows7-旗舰版
工具:Eclipse MARS,Navicat Premium 12
JDK:1.8.0_121
Tomcat:8.0.43
MySQL :5.6.5-m8
二.搭建流程:
一.环境准备
1.1 配置JDK
在window--》Preferences下搜索Java,选择本地对应的JDK安装目录,点击添加完成:
配置完开发环境JDK后,需要修改项目默认的编译环境:
1.2 配置Tomcat
在window--》Preferences下搜索Server,选择自己本地对应的Tomcat版本及JRE环境,点击添加完成:
添加完成之后,配置Tomcat,如图所示,分别对应项目发布路径、自动部署、发布超时时间、访问端口等配置
1.3 配置Maven
在window--》Preferences下搜索Maven,选择本地Maven安装路径:
添加Maven后配置自定义属性,替换自己的Maven settings配置文件及Maven仓库:
二.创建项目
2.1 使用Eclipse创建Maven项目:
2.2 项目创建完成后,根据自己习惯的包名结构创建对应的目录,项目结构如图所示:
三.配置pom.xml依赖
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>com</groupId> 6 <artifactId>mySpringMVC</artifactId> 7 <packaging>war</packaging> 8 <version>0.0.1-SNAPSHOT</version> 9 <name>mySpringMVC Maven Webapp</name> 10 <url>http://maven.apache.org</url> 11 12 <properties> 13 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 14 15 <jdk.version>1.8</jdk.version> 16 <spring.version>4.1.9.RELEASE</spring.version> 17 <aspectj.version>1.8.9</aspectj.version> 18 <mysql-connector>8.0.13</mysql-connector> 19 <druid.version>1.0.18</druid.version> 20 <mybatis.version>3.2.8</mybatis.version> 21 <mybatis-spring.version>1.2.3</mybatis-spring.version> 22 <mybatis-generator.version>1.3.5</mybatis-generator.version> 23 <shiro.version>1.2.3</shiro.version> 24 </properties> 25 26 <!-- 定义Maven项目依赖 --> 27 <dependencies> 28 <!-- Junit 测试依赖 --> 29 <dependency> 30 <groupId>junit</groupId> 31 <artifactId>junit</artifactId> 32 <version>3.8.1</version> 33 <!-- 表示开发的时候引入,发布的时候不会加载此包 --> 34 <scope>test</scope> 35 </dependency> 36 37 <!-- spring核心依赖 --> 38 <dependency> 39 <groupId>org.springframework</groupId> 40 <artifactId>spring-core</artifactId> 41 <version>${spring.version}</version> 42 </dependency> 43 44 <!-- springWeb依赖 --> 45 <dependency> 46 <groupId>org.springframework</groupId> 47 <artifactId>spring-web</artifactId> 48 <version>${spring.version}</version> 49 </dependency> 50 51 <!-- springMVC依赖 --> 52 <dependency> 53 <groupId>org.springframework</groupId> 54 <artifactId>spring-webmvc</artifactId> 55 <version>${spring.version}</version> 56 </dependency> 57 58 <!-- springJDBC依赖 --> 59 <dependency> 60 <groupId>org.springframework</groupId> 61 <artifactId>spring-jdbc</artifactId> 62 <version>${spring.version}</version> 63 </dependency> 64 65 <!-- spring上下文依赖 --> 66 <dependency> 67 <groupId>org.springframework</groupId> 68 <artifactId>spring-context</artifactId> 69 <version>${spring.version}</version> 70 </dependency> 71 72 <!-- spring上下文支持依赖 --> 73 <dependency> 74 <groupId>org.springframework</groupId> 75 <artifactId>spring-context-support</artifactId> 76 <version>${spring.version}</version> 77 </dependency> 78 79 <!-- springAOP依赖 --> 80 <dependency> 81 <groupId>org.springframework</groupId> 82 <artifactId>spring-aop</artifactId> 83 <version>${spring.version}</version> 84 </dependency> 85 86 <!-- aspectj依赖 --> 87 <dependency> 88 <groupId>org.aspectj</groupId> 89 <artifactId>aspectjrt</artifactId> 90 <version>${aspectj.version}</version> 91 </dependency> 92 93 <dependency> 94 <groupId>org.aspectj</groupId> 95 <artifactId>aspectjweaver</artifactId> 96 <version>${aspectj.version}</version> 97 </dependency> 98 99 <dependency> 100 <groupId>cglib</groupId> 101 <artifactId>cglib</artifactId> 102 <version>3.1</version> 103 </dependency> 104 105 <!-- spring测试依赖 --> 106 <dependency> 107 <groupId>org.springframework</groupId> 108 <artifactId>spring-test</artifactId> 109 <version>${spring.version}</version> 110 </dependency> 111 112 <!-- spring OXM依赖 --> 113 <dependency> 114 <groupId>org.springframework</groupId> 115 <artifactId>spring-oxm</artifactId> 116 <version>${spring.version}</version> 117 </dependency> 118 119 <!-- spring 事务依赖 --> 120 <dependency> 121 <groupId>org.springframework</groupId> 122 <artifactId>spring-tx</artifactId> 123 <version>${spring.version}</version> 124 </dependency> 125 126 <!-- Servlet依赖 --> 127 <dependency> 128 <groupId>javax.servlet</groupId> 129 <artifactId>javax.servlet-api</artifactId> 130 <version>3.0.1</version> 131 <scope>provided</scope> 132 </dependency> 133 134 <dependency> 135 <groupId>javax.servlet</groupId> 136 <artifactId>jstl</artifactId> 137 <version>1.1.2</version> 138 <scope>provided</scope> 139 </dependency> 140 141 <!-- jsp依赖 --> 142 <dependency> 143 <groupId>javax.servlet.jsp</groupId> 144 <artifactId>javax.servlet.jsp-api</artifactId> 145 <version>2.3.1</version> 146 <scope>provided</scope> 147 </dependency> 148 149 <!-- jackson 依赖 --> 150 <dependency> 151 <groupId>org.codehaus.jackson</groupId> 152 <artifactId>jackson-jaxrs</artifactId> 153 <version>1.9.11</version> 154 </dependency> 155 156 <!-- commons 依赖 --> 157 <dependency> 158 <groupId>org.apache.commons</groupId> 159 <artifactId>commons-lang3</artifactId> 160 <version>3.3.2</version> 161 </dependency> 162 163 <dependency> 164 <groupId>commons-io</groupId> 165 <artifactId>commons-io</artifactId> 166 <version>2.4</version> 167 </dependency> 168 169 <dependency> 170 <groupId>org.apache.commons</groupId> 171 <artifactId>commons-collections4</artifactId> 172 <version>4.0</version> 173 </dependency> 174 175 <dependency> 176 <groupId>commons-logging</groupId> 177 <artifactId>commons-logging</artifactId> 178 <version>1.1.3</version> 179 </dependency> 180 181 <dependency> 182 <groupId>commons-codec</groupId> 183 <artifactId>commons-codec</artifactId> 184 <version>1.8</version> 185 </dependency> 186 <dependency> 187 <groupId>commons-beanutils</groupId> 188 <artifactId>commons-beanutils</artifactId> 189 <version>1.8.3</version> 190 </dependency> 191 192 <dependency> 193 <groupId>commons-chain</groupId> 194 <artifactId>commons-chain</artifactId> 195 <version>1.2</version> 196 </dependency> 197 198 <dependency> 199 <groupId>commons-fileupload</groupId> 200 <artifactId>commons-fileupload</artifactId> 201 <version>1.3.1</version> 202 </dependency> 203 204 <dependency> 205 <groupId>org.apache.commons</groupId> 206 <artifactId>commons-math3</artifactId> 207 <version>3.3</version> 208 </dependency> 209 210 <dependency> 211 <groupId>org.apache.commons</groupId> 212 <artifactId>commons-pool2</artifactId> 213 <version>2.2</version> 214 </dependency> 215 216 <dependency> 217 <groupId>org.apache.commons</groupId> 218 <artifactId>commons-digester3</artifactId> 219 <version>3.2</version> 220 </dependency> 221 222 <dependency> 223 <groupId>commons-net</groupId> 224 <artifactId>commons-net</artifactId> 225 <version>3.3</version> 226 </dependency> 227 228 <dependency> 229 <groupId>commons-dbutils</groupId> 230 <artifactId>commons-dbutils</artifactId> 231 <version>1.5</version> 232 </dependency> 233 234 <dependency> 235 <groupId>org.apache.commons</groupId> 236 <artifactId>commons-email</artifactId> 237 <version>1.3.3</version> 238 </dependency> 239 240 <dependency> 241 <groupId>commons-dbcp</groupId> 242 <artifactId>commons-dbcp</artifactId> 243 <version>1.4</version> 244 </dependency> 245 246 <!-- jstl依赖 --> 247 <dependency> 248 <groupId>jstl</groupId> 249 <artifactId>jstl</artifactId> 250 <version>1.2</version> 251 </dependency> 252 253 <!-- 标签库依赖 --> 254 <dependency> 255 <groupId>taglibs</groupId> 256 <artifactId>standard</artifactId> 257 <version>1.1.2</version> 258 </dependency> 259 260 <!-- 日志相关 --> 261 <dependency> 262 <groupId>log4j</groupId> 263 <artifactId>log4j</artifactId> 264 <version>1.2.16</version> 265 </dependency> 266 267 <dependency> 268 <groupId>org.slf4j</groupId> 269 <artifactId>slf4j-api</artifactId> 270 <version>1.7.5</version> 271 </dependency> 272 273 <!-- 阿里连接池依赖 --> 274 <dependency> 275 <groupId>com.alibaba</groupId> 276 <artifactId>druid</artifactId> 277 <version>${druid.version}</version> 278 </dependency> 279 280 <!-- 阿里fastjson依赖 --> 281 <dependency> 282 <groupId>com.alibaba</groupId> 283 <artifactId>fastjson</artifactId> 284 <version>1.1.41</version> 285 </dependency> 286 287 <!-- 引入jackson,防止ajax调用返回json出现下载文件 --> 288 <dependency> 289 <groupId>com.fasterxml.jackson.core</groupId> 290 <artifactId>jackson-databind</artifactId> 291 <version>2.5.1</version> 292 </dependency> 293 294 <!-- mysql连接 --> 295 <dependency> 296 <groupId>mysql</groupId> 297 <artifactId>mysql-connector-java</artifactId> 298 <version>${mysql-connector}</version> 299 </dependency> 300 301 <!-- MyBatis --> 302 <dependency> 303 <groupId>org.mybatis</groupId> 304 <artifactId>mybatis</artifactId> 305 <version>${mybatis.version}</version> 306 </dependency> 307 308 <!-- MyBatis/Spring包 --> 309 <dependency> 310 <groupId>org.mybatis</groupId> 311 <artifactId>mybatis-spring</artifactId> 312 <version>${mybatis-spring.version}</version> 313 </dependency> 314 315 <!-- MyBatis Generator 反向生成 --> 316 <dependency> 317 <groupId>org.mybatis.generator</groupId> 318 <artifactId>mybatis-generator-core</artifactId> 319 <version>${mybatis-generator.version}</version> 320 </dependency> 321 322 <!-- MyBatis分页插件依赖 --> 323 <dependency> 324 <groupId>com.github.pagehelper</groupId> 325 <artifactId>pagehelper</artifactId> 326 <version>4.0.0</version> 327 </dependency> 328 329 <!-- Shiro安全验证依赖 --> 330 <dependency> 331 <groupId>org.apache.shiro</groupId> 332 <artifactId>shiro-core</artifactId> 333 <version>${shiro.version}</version> 334 </dependency> 335 336 <dependency> 337 <groupId>org.apache.shiro</groupId> 338 <artifactId>shiro-web</artifactId> 339 <version>${shiro.version}</version> 340 </dependency> 341 342 <dependency> 343 <groupId>org.apache.shiro</groupId> 344 <artifactId>shiro-spring</artifactId> 345 <version>${shiro.version}</version> 346 </dependency> 347 348 <dependency> 349 <groupId>org.apache.shiro</groupId> 350 <artifactId>shiro-ehcache</artifactId> 351 <version>${shiro.version}</version> 352 </dependency> 353 </dependencies> 354 355 <build> 356 <!-- 定义配置文件的路径 --> 357 <resources> 358 <resource> 359 <directory>src/main/resources</directory> 360 <filtering>true</filtering> 361 </resource> 362 </resources> 363 364 <finalName>mySpringMVC</finalName> 365 366 <plugins> 367 <!-- 定义mybatis generator 反向生成插件 --> 368 <plugin> 369 <groupId>org.mybatis.generator</groupId> 370 <artifactId>mybatis-generator-maven-plugin</artifactId> 371 <version>1.3.2</version> 372 <executions> 373 <execution> 374 <id>Generate MyBatis Files</id> 375 <goals> 376 <goal>generate</goal> 377 </goals> 378 <phase>generate</phase> 379 <configuration> 380 <verbose>true</verbose> 381 <overwrite>true</overwrite> 382 </configuration> 383 </execution> 384 </executions> 385 386 <dependencies> 387 <dependency> 388 <groupId>mysql</groupId> 389 <artifactId>mysql-connector-java</artifactId> 390 <version>${mysql-connector}</version> 391 </dependency> 392 393 <dependency> 394 <groupId>org.mybatis.generator</groupId> 395 <artifactId>mybatis-generator-core</artifactId> 396 <version>${mybatis-generator.version}</version> 397 </dependency> 398 399 400 <dependency> 401 <groupId>org.mybatis</groupId> 402 <artifactId>mybatis</artifactId> 403 <version>${mybatis.version}</version> 404 </dependency> 405 </dependencies> 406 </plugin> 407 </plugins> 408 </build> 409 410 </project>