SpringBoot是spring家族中的一个全新框架,用来简化spring程序的创建和开发过程。在以往我们通过SpringMVC+Spring+Mybatis框架进行开发的时候,我们需要配置web.xml,spring配置,mybatis配置,然后整合在一起,而SpringBoot抛弃了繁琐的xml配置过程,采用大量默认的配置来简化我们的spring开发过程。SpringBoot化繁为简,使开发变得更加的简单迅速。
优点
创建独立Spring应用
内嵌web服务器
自动starter依赖,简化构建配置
自动配置Spring以及第三方功能
提供生产级别的监控、健康检查及外部化配置
无代码生成、无需编写XML
SpringBoot是整合Spring技术栈的一站式框架
SpringBoot是简化Spring技术栈的快速开发脚手架
缺点
迭代快,需要时刻关注变化
查看版本新特性 https://github.com/spring-projects/spring-boot/wiki#release-notes
封装太深,内部原理复杂,不容易精通
入门使用
相关依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<!--web场景启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
当引入spring-boot-starter-web模块的依赖,并会引入tomcat服务器、SpringMVC等依赖
它内嵌了Tomcat并且提供了默认的配置,比如默认端口是8080.我们可以在application.properties或者application.yml中配置更改端口号
主程序
//告诉SpringBoot,这是一个SpringBoot应用
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
controller层
//@ResponseBody //返回一段话,而不是跳转到某个页面
//@Controller
@RestController //@ResponseBody与@Controller的合体
public class HelloController {
@RequestMapping("/hello") //映射请求
public String handle01(){
return "Hello,SpringBoot2"; //向浏览器返回
}
}
直接启动main方法,并访问URL: http://ip:port/hello
简单部署
<build>
<plugins>
<plugin>
<gr