Build Systems
强烈建议你选择支持 dependency management并且能够使用已发布到 "`Maven Central`"存储库中的工件的构建系统。我们建议你选择 Maven 或 Gradle。Spring Boot 有可能与其他构建系统(例如 Ant)配合使用,但它们的支持不是特别好。
It is strongly recommended that you choose a build system that supports dependency management and that can consume artifacts published to the “Maven Central” repository. We would recommend that you choose Maven or Gradle. It is possible to get Spring Boot to work with other build systems (Ant, for example), but they are not particularly well supported.
Dependency Management
Spring Boot 的每个版本都会提供它支持的经过整理的依赖项列表。事实上,你不需要在构建配置中为这些依赖项中的任何一个提供版本,因为 Spring Boot 会为你管理这些版本。当你升级 Spring Boot 本身时,这些依赖项也会以一致的方式进行升级。
Each release of Spring Boot provides a curated list of dependencies that it supports. In practice, you do not need to provide a version for any of these dependencies in your build configuration, as Spring Boot manages that for you. When you upgrade Spring Boot itself, these dependencies are upgraded as well in a consistent way.
如果你有需要,你仍然可以指定一个版本并覆盖 Spring Boot 的建议。 |
You can still specify a version and override Spring Boot’s recommendations if you need to do so. |
经过整理的列表包含你可以与 Spring Boot 一起使用的所有 Spring 模块,以及经过整理的第三方库列表。可以使用与 Maven和 Gradle一起使用的标准物料清单 (spring-boot-dependencies
) 获取此列表。
The curated list contains all the Spring modules that you can use with Spring Boot as well as a refined list of third party libraries.
The list is available as a standard Bills of Materials (spring-boot-dependencies
) that can be used with both Maven and Gradle.
Spring Boot 的每个版本都与 Spring Framework 的基础版本相关联。我们 *highly*建议你不要指定它的版本。
Each release of Spring Boot is associated with a base version of the Spring Framework. We highly recommend that you do not specify its version.
Ant
可以使用 Apache Ant+Ivy 构建 Spring Boot 项目。spring-boot-antlib
"`AntLib`"模块也可用于帮助 Ant 创建可执行的 jar。
It is possible to build a Spring Boot project using Apache Ant+Ivy.
The spring-boot-antlib
“AntLib” module is also available to help Ant create executable jars.
若要声明依赖项,一个典型的 `ivy.xml`文件类似于以下示例:
To declare dependencies, a typical ivy.xml
file looks something like the following example:
<ivy-module version="2.0">
<info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
<configurations>
<conf name="compile" description="everything needed to compile this module" />
<conf name="runtime" extends="compile" description="everything needed to run this module" />
</configurations>
<dependencies>
<dependency org="org.springframework.boot" name="spring-boot-starter"
rev="${spring-boot.version}" conf="compile" />
</dependencies>
</ivy-module>
一个典型的 `build.xml`类似于以下示例:
A typical build.xml
looks like the following example:
<project
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:spring-boot="antlib:org.springframework.boot.ant"
name="myapp" default="build">
<property name="spring-boot.version" value="{version-spring-boot}" />
<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />
</target>
<target name="classpaths" depends="resolve">
<path id="compile.classpath">
<fileset dir="lib/compile" includes="*.jar" />
</path>
</target>
<target name="init" depends="classpaths">
<mkdir dir="build/classes" />
</target>
<target name="compile" depends="init" description="compile">
<javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" />
</target>
<target name="build" depends="compile">
<spring-boot:exejar destfile="build/myapp.jar" classes="build/classes">
<spring-boot:lib>
<fileset dir="lib/runtime" />
</spring-boot:lib>
</spring-boot:exejar>
</target>
</project>
如果你不想使用 `spring-boot-antlib`模块,请参阅 Build an Executable Archive From Ant without Using spring-boot-antlib “How-to”。 |
If you do not want to use the |
Starters
启动程序是一组方便的依赖关系描述符,你可以将其包含在你的应用程序中。你可以获得所有你需要的 Spring 及相关技术的一站式服务,而无需搜索示例代码并复制粘贴大量的依赖关系描述符。例如,如果你想开始使用 Spring 和 JPA 进行数据库访问,请在你的项目中包含 spring-boot-starter-data-jpa
依赖项。
Starters are a set of convenient dependency descriptors that you can include in your application.
You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors.
For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa
dependency in your project.
启动程序包含大量依赖项,你需要这些依赖项才能快速启动并运行项目,并拥有一个一致且受支持的已管理传递性依赖项集。
The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies.
所有 official 启动程序都遵循类似的命名模式; spring-boot-starter-
, where 是特定类型的应用程序。此命名结构旨在在你需要找到启动程序时帮助你。许多 IDE 中的 Maven 集成让你可以按名称搜索依赖项。例如,在安装了适当的 Eclipse 或 Spring 工具插件后,你可以在 POM 编辑器中按
ctrl-space
并键入 “spring-boot-starter” 以获取完整列表。
All official starters follow a similar naming pattern; spring-boot-starter-
, where is a particular type of application.
This naming structure is intended to help when you need to find a starter.
The Maven integration in many IDEs lets you search dependencies by name.
For example, with the appropriate Eclipse or Spring Tools plugin installed, you can press
ctrl-space
in the POM editor and type “spring-boot-starter” for a complete list.
如 “Creating Your Own Starter” 部分中所述,第三方启动程序不应以 spring-boot
开头,因为它专用于官方 Spring Boot 工件。相反,第三方启动程序通常以项目名称开头。例如,名为 thirdpartyproject
的第三方启动项目项目通常命名为 thirdpartyproject-spring-boot-starter
。
As explained in the “Creating Your Own Starter” section, third party starters should not start with spring-boot
, as it is reserved for official Spring Boot artifacts.
Rather, a third-party starter typically starts with the name of the project.
For example, a third-party starter project called thirdpartyproject
would typically be named thirdpartyproject-spring-boot-starter
.
以下是 Spring Boot 在 org.springframework.boot
组下提供的应用程序启动程序:
The following application starters are provided by Spring Boot under the org.springframework.boot
group:
Unresolved include directive in modules/ROOT/pages/using/build-systems.adoc - include::ROOT:partial$starters/application-starters.adoc[]
除了应用程序启动程序外,还可以使用以下启动程序添加 production ready 功能:
In addition to the application starters, the following starters can be used to add production ready features:
Unresolved include directive in modules/ROOT/pages/using/build-systems.adoc - include::ROOT:partial$starters/production-starters.adoc[]
最后,Spring Boot 还包括以下启动程序,如果你想排除或交换特定的技术方面,可以使用它们:
Finally, Spring Boot also includes the following starters that can be used if you want to exclude or swap specific technical facets:
Unresolved include directive in modules/ROOT/pages/using/build-systems.adoc - include::ROOT:partial$starters/technical-starters.adoc[]
要了解如何交换技术方面,请参阅 swapping web server 和 logging system 的操作说明文档。
To learn how to swap technical facets, please see the how-to documentation for swapping web server and logging system.
有关其他社区贡献的启动程序列表,请参阅 GitHub 上 |
For a list of additional community contributed starters, see the {code-spring-boot-latest}/spring-boot-project/spring-boot-starters/README.adoc[README file] in the |