Build Systems

强烈建议你选择支持 dependency management并且能够使用已发布到 "`Maven Central`"存储库中的工件的构建系统。我们建议你选择 Maven 或 Gradle。Spring Boot 有可能与其他构建系统(例如 Ant)配合使用,但它们的支持不是特别好。

Dependency Management

Spring Boot 的每个版本都会提供它支持的经过整理的依赖项列表。事实上,你不需要在构建配置中为这些依赖项中的任何一个提供版本,因为 Spring Boot 会为你管理这些版本。当你升级 Spring Boot 本身时,这些依赖项也会以一致的方式进行升级。

如果你有需要,你仍然可以指定一个版本并覆盖 Spring Boot 的建议。

经过整理的列表包含你可以与 Spring Boot 一起使用的所有 Spring 模块,以及经过整理的第三方库列表。可以使用与 MavenGradle一起使用的标准物料清单 (spring-boot-dependencies) 获取此列表。

Spring Boot 的每个版本都与 Spring Framework 的基础版本相关联。我们 *highly*建议你不要指定它的版本。

Maven

若要了解如何将 Spring Boot 与 Maven 配合使用,请参阅 Spring Boot 的 Maven 插件的文档:

Gradle

若要了解如何将 Spring Boot 与 Gradle 配合使用,请参阅 Spring Boot 的 Gradle 插件的文档:

Ant

可以使用 Apache Ant+Ivy 构建 Spring Boot 项目。spring-boot-antlib "`AntLib`"模块也可用于帮助 Ant 创建可执行的 jar。

若要声明依赖项,一个典型的 `ivy.xml`文件类似于以下示例:

<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`类似于以下示例:

<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”。

Starters

启动程序是一组方便的依赖关系描述符,你可以将其包含在你的应用程序中。你可以获得所有你需要的 Spring 及相关技术的一站式服务,而无需搜索示例代码并复制粘贴大量的依赖关系描述符。例如,如果你想开始使用 Spring 和 JPA 进行数据库访问,请在你的项目中包含 spring-boot-starter-data-jpa 依赖项。

启动程序包含大量依赖项,你需要这些依赖项才能快速启动并运行项目,并拥有一个一致且受支持的已管理传递性依赖项集。

What is in a name

所有 official 启动程序都遵循类似的命名模式; spring-boot-starter-, where 是特定类型的应用程序。此命名结构旨在在你需要找到启动程序时帮助你。许多 IDE 中的 Maven 集成让你可以按名称搜索依赖项。例如,在安装了适当的 Eclipse 或 Spring 工具插件后,你可以在 POM 编辑器中按 ctrl-space 并键入 “spring-boot-starter” 以获取完整列表。 如 “Creating Your Own Starter” 部分中所述,第三方启动程序不应以 spring-boot 开头,因为它专用于官方 Spring Boot 工件。相反,第三方启动程序通常以项目名称开头。例如,名为 thirdpartyproject 的第三方启动项目项目通常命名为 thirdpartyproject-spring-boot-starter

以下是 Spring Boot 在 org.springframework.boot 组下提供的应用程序启动程序:

Spring Boot application starters

Unresolved include directive in modules/reference/pages/using/build-systems.adoc - include::ROOT:partial$starters/application-starters.adoc[]

除了应用程序启动程序外,还可以使用以下启动程序添加 production ready 功能:

Spring Boot production starters

Unresolved include directive in modules/reference/pages/using/build-systems.adoc - include::ROOT:partial$starters/production-starters.adoc[]

最后,Spring Boot 还包括以下启动程序,如果你想排除或交换特定的技术方面,可以使用它们:

Spring Boot technical starters

Unresolved include directive in modules/reference/pages/using/build-systems.adoc - include::ROOT:partial$starters/technical-starters.adoc[]

要了解如何交换技术方面,请参阅 swapping web serverlogging system 的操作说明文档。

有关其他社区贡献的启动程序列表,请参阅 GitHub 上 spring-boot-starters 模块中的 {code-spring-boot-latest}/spring-boot-project/spring-boot-starters/README.adoc[自述文件]。