一、方式一:spring-boot-starter-parent
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
進入spring-boot-starter-parent里,可以發現它其實依賴了我們下面要講的spring-boot-dependencies模塊 。
二、方式二:使用spring-boot-dependencies
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
使用這種方式就不用繼承父模塊,可以解決單繼承的問題。這樣就可以繼承其他父模塊,比如自己創建的父模塊。
scope=import,type=pom表示在此pom中引入spring-boot-dependencies的pom的所有內容,注意只能在dependencyManagement中使用。
大多數我們可能用到的包依賴和插件依賴都已經在spring-boot-dependencies中定義好了