<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
是 Spring Boot 的父级依赖,加上此配置之后,当前的项目就是 Spring Boot 项目了。spring-boot-starter-parent 是一个特殊的 starter,它用来提供相关的 Maven 默认依赖。
我们的项目的父级依赖是 spring-boot-starter-parent , spring-boot-starter-parent 的父级依赖是 spring-boot-dependencies 。
spring-boot-starter-parent 中的默认配置可以通过覆盖的方式修改!
<properties>
<java.version>1.8</java.version>
</properties>
<properties>
<project.build.sourceEncoding>GBK</project.build.sourceEncoding>
</properties>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.5.3</version>
</dependency>
会自动继承 spring-boot-starter-parent 中的写法!
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
自定义项目的父级依赖!
不再使用父级依赖 spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<!-- 此处需要带上版本信息 -->
<version>2.5.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<jpa.version>2.5.3</jpa.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<!-- 此处需要引用版本信息 -->
<version>${jpa.version}</version>
</dependency>
直接仿写 spring-boot-starter-parent 默认配置!
<!-- 编译时指定jdk版本-->
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
创建 Spring Boot 项目的时候默认自带,如果普通的 Maven 项目配置成 Spring Boot 项目,则加入以下配置!直接仿写 spring-boot-starter-parent 默认配置即可!
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>