1.搭建Spring boot

一、Spring boot简介

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。其实它就是一套集成好的类库,将平时搭建Spring MVC 的依赖都集成在一起,并以一种简单的约定将其运行起来。

  • Create stand-alone Spring applications
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • Provide opinionated ‘starter’ dependencies to simplify your build configuration
  • Automatically configure Spring and 3rd party libraries whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

官网描述有5个特性:

  1. 能独立运行的Spring应用
  2. 内嵌Tomcat、Jetty或者Undertow (无需WAR包)
  3. 提供自用的start依赖去简化你的开发环境搭建
  4. 尽可能自动配置Spring和第三方的类库
  5. 没有代码生成,也无需XML配置。

二、搭建开发环境

下载项目

我们访问官网的quick start:https://start.spring.io/

写好自己项目的GA(Group Artifact),点击Generate project,如图所示

然后,我们会得到一个压缩包。解压后,我们将项目导入IDE,我们的第一步就完成了。

配置依赖

在pom.xml文件里面加入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- 数据库连接池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>

<!-- mysql jdbc -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<!-- jsp和jSTL依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>