之前在SpringMVC中整合MyBatis和Spring,以及其他的一些框架时,我们需要手动配置很多文件,对于这些文件的配置,基本都是一些重复性的工作,SpringBoot就是为了解决这些问题而产生的
SpringBoot版本可以在Spring官方找到:

tag的含义为:
SpringBoot有两种集成方式:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!--继承父maven-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SpringBootConfigure1</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project><?xml version="1.0" encoding="UTF-8"?>
<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">
<!--导入依赖-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modelVersion>4.0.0</modelVersion>
<artifactId>SpringBootConfigure1</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>除了手动创建外,还可以使用idel自带的springBoot项目初始化插件:


SpringBoot内置了tomcat,所以并不需要配置tomcat,项目类型也可以是一个jar项目,所以启动服务的方法就是启动类中的main方法

@SpringBootApplication
public class SpringBootConfigure2Application {
public static void main(String[] args) {
SpringApplication.run(SpringBootConfigure2Application.class, args);
}
}@SpringBootApplication注解必须加上,该注解为SpringBoot的入口,会做一系列初始化操作,并自动启用包扫描,扫描的包为:启动类所在包下的所有类,将它们注册到Spring容器中

随便写一个接口测试:
@Controller
public class MyController {
@RequestMapping("hello")
@ResponseBody
public String hello() {
return "hell";
}
}执行main方法,浏览器访问:

SpringBoot中地址默认不带项目名,直接访问即可
SpringBoot整合了很多框架,预制了很多配置,所以也有自己的配置文件,如果想要知道它有哪些配置项,可以去官网查询:https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties
SpringBoot支持三种配置文件格式:yml yaml properties 三种文件可配置的项都是一样的,一般使用的是yml,接下来简单的使用该配置文件
在resources目录下新建application.yml文件:

修改项目启动的上下文路径和端口号:
server:
port: 8090
servlet:
context-path: /springboot注意":"后面需要跟一个空格
上面内容相当于properties文件中的:
server.port=8090
server.servlet.context-path=/springboot重新启动下,浏览器访问:

除了预制的配置项外,yml还可以定义对象:
person:
name: 张三
age: 18
gender: 男json格式定义对象:
person2: { name: 张三,age: 18,gender: 男 }配置数组类型:
city:
- beijing
- nanjingjson格式:
city2: [ beijing,nanjing ]除了在resources目录下,SpringBoot的配置文件还能存放在下面三个目录:
一般也就是在resources目录下