Spring Boot 3.x 构建系统&Starters
系列文章目录
系列文章:Spring Boot 3.x 系列教程
文章目录
- 系列文章目录
- 前言
- 一、依赖管理
- 二、Maven
- 三、Spring Boot Maven Plugin
- 四、Starters
前言
Spring Boot 建议选择一个支持依赖项管理并能够使用发布到“Maven Central”存储库的构件的构建系统。一般可以选择Maven或Gradle。让Spring Boot与其他构建系统(例如Ant)一起工作是可能的,但它们并没有得到很好的支持。本文只介绍常用的Maven。
一、依赖管理
Spring Boot的每个版本都提供了一个它所支持的依赖项列表。在实践中,你不需要在构建配置中为这些依赖项提供一个版本,因为Spring Boot会为你管理它。当你升级Spring Boot本身时,这些依赖项也会以一致的方式升级。
二、Maven
maven项目引入Spring Boot框架有两种方式:
1. 继承spring-boot-starter-parent
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M2</version>
</parent>
这种方式只需要指定Spring Boot parent版本号,如果需要引入其它的starter无需指定版本。
使用这种方式,还可以通过覆盖自己项目中的属性来覆盖各个依赖项。例如,要使用不同版本的SLF4J库,你需要将以下内容添加到pom.xml中:
<properties>
<slf4j.version>1.7.30</slf4j.version>
</properties>
2. dependencyManagement