目录

Spring Boot - Build Systems

在Spring Boot中,选择构建系统是一项重要任务。 我们建议使用Maven或Gradle,因为它们可以为依赖关系管理提供良好的支持。 Spring不支持其他构建系统。

依赖管理

Spring Boot团队提供了一个依赖项列表,以支持每个版本的Spring Boot版本。 您无需在构建配置文件中提供依赖项版本。 Spring Boot会根据版本自动配置依赖项版本。 请记住,升级Spring Boot版本时,依赖项也会自动升级。

Note - 如果要指定依赖项的版本,可以在配置文件中指定它。 但是,Spring Boot团队强烈建议不要指定依赖项的版本。

Maven依赖

对于Maven配置,我们应该继承Spring Boot Starter父项目来管理Spring Boot Starters依赖项。 为此,我们只需在pom.xml文件中继承启动父级,如下所示。

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>1.5.8.RELEASE</version>
</parent>

我们应该指定Spring Boot Parent Starter依赖项的版本号。 然后,对于其他启动器依赖项,我们不需要指定Spring Boot版本号。 观察下面给出的代码 -

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
   </dependency>
</dependencies>

Gradle Dependency

我们可以将Spring Boot Starters依赖项直接导入build.gradle文件。 我们不需要Spring Boot启动父依赖,例如Maven for Gradle。 观察下面给出的代码 -

buildscript {
   ext {
      springBootVersion = '1.5.8.RELEASE'
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

同样,在Gradle中,我们不需要为依赖项指定Spring Boot版本号。 Spring Boot会根据版本自动配置依赖项。

dependencies {
   compile('org.springframework.boot:spring-boot-starter-web')
}
↑回到顶部↑
WIKI教程 @2018