前言

​ 本次学习的SpringBoot版本为2.1.3.RELEASE,同时文档内容有点多,只会拿出个人认为要学习的部分来学习

直接继承Starter Parent

pom.xml文件中添加以下代码:

1
2
3
4
5
6
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>

您要在此依赖项上指定Spring Boot版本号。如果导入其他启动器,则可以省略版本号。

我们还可以通过properties来更好的管理版本信息

1
2
3
<properties>
<spring-boot.version>2.1.3.RELEASE</spring-boot.version>
</properties>

然后在指定版本号处指定引入的设置的属性值

1
2
3
4
5
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring-boot.version}</version>
</dependency>

在父pom中引用

不是每个人都喜欢从spring-boot-starter-parentPOM 继承。您可能拥有自己需要使用的公司标准父级,或者您可能更愿意明确声明所有Maven配置。

如果您不想使用spring-boot-starter-parent,您仍然可以通过使用scope=import依赖项来保持依赖项管理(但不是插件管理)的好处 ,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

如上所述,前面的示例设置不允许您使用属性覆盖单个依赖项。要获得相同的结果,您需要在输入之前在dependencyManagement项目中添加一个 条目。例如,要升级到另一个Spring Data版本系列,您可以将以下元素添加到pom.xmlspring-boot-dependencies

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>