在Spring Boot中,选择构建系统是一项重要任务。无涯教程建议使用Maven或Gradle,因为它们为依赖项管理提供了良好的支持。
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 文件中。不需要像Maven for Gradle这样的Spring Boot start Parent依赖项。
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') }
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)