1. 什么是Spring boot
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。
2. Spring boot有什么好处
1)简化配置,去掉繁琐的xml配置。
2)使开发更加简单。
3)内置web应用服务器,运行更加方便!
3 快速入门
软件环境:
开发软件:idea 2018.2.4
jdk版本: jdk1.8.0_19
maven版本:3.5.4
构建步骤:
第一步:创建一个Spring boot项目
项目目录机构介绍:
pom文件说明:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
指定了父模块spring-boot-starter-parent,解决了今后我们引入spring boot第三方模块版本依赖问题。
依赖核心模块:
<!-- web 的核心模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 测试模块依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
编写第一个应用
1)新建一个controller的文件夹并创建一个HelloController的类:
@RestController
public class HellController {
@RequestMapping("/hello")
public String hello(){
return "hello Spring Boot!";
}
}
启动Application.java类,出现如下日志信息,说明第一个Spring boot应用已经启动成功了。
我们通过http://localhost:8080/hello 就可以看到我们的结果了。