每个springboot项目的maven配置文件pom.xml中都有这样一个父项目,用来做依赖管理,几乎声明了我们开发中所有常用的依赖的版本号,这样子项目继承父项目就不需要版本号了

1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>

spring-boot-dependencies-2.3.4.RELEASE.pom文件,spring-bootdependencies的父项目,几乎声明了开发中所有常用依赖的版本号,称为springboot的自动版本仲裁机制

image-20220815194555902

这样在我们的pm.xml中,引入这里面声明版本的依赖时,就不需要写版本号了

例如引入spring-boot-starter-web模块,可以不写版本号

1
2
3
4
5
6
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

以上是默认情况,那么如何引入自定义版本呢?

例如springbot默认mysql驱动版本是8.0.21

image-20220815195153250

我们想要5.1.43版本,可以自己在pom.xml中指定版本号,这个称为maven的就近优先原则

1
2
3
<properties>
<mysql.version>5.1.43</mysql.version>
</properties>

springboot提供了许多的start,名称是以spring-boot-start-来命名的,可以让我们快速引入某个开发场景的常规所有依赖,如web开发场景,start为spring-boot-start-web

以下是springboot的一部分start

springboot所有支持的场景都可以在文档中找到

https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter

image-20220815200014048

所有的*-spring-boot-starter都是第三方的start,如mybatis-spring-boot-starter