在Spring Boot中,选择构建系统是一项重要任务.我们建议使用Maven或Gradle,因为它们可以为依赖关系管理提供良好的支持. Spring不支持其他构建系统.
Spring Boot团队提供了一个依赖关系列表,以支持Spring Boot版本发布.您无需在构建配置文件中提供依赖项版本. Spring Boot会根据版本自动配置依赖项版本.请记住,当您升级Spring Boot版本时,依赖项也会自动升级.
注意 : 如果要指定依赖项的版本,可以在配置文件中指定它.但是,Spring Boot团队强烈建议不要指定依赖的版本.
对于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>
我们可以将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') }