构建系统

强烈建议你选择一个支持 依赖管理 并且可以使用发布到 Maven Central 仓库的构件的构建系统。 我们建议你选择 Maven 或 Gradle。 虽然可以让 Spring Boot 与其他构建系统(例如 Ant)一起工作,但它们并没有得到特别好的支持。

依赖管理

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

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

这个精选列表包含了你可以在 Spring Boot 中使用的所有 Spring 模块以及精选的第三方库列表。 该列表作为标准的物料清单(spring-boot-dependencies)提供,可以与 MavenGradle 一起使用。

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

Maven

要了解如何在 Maven 中使用 Spring Boot,请参阅 Spring Boot 的 Maven 插件文档:

Gradle

要了解如何在 Gradle 中使用 Spring Boot,请参阅 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="3.4.6" />

	<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 模块,请参阅 “How-to Guides” 中的 在不使用 spring-boot-antlib 的情况下使用 Ant 构建可执行归档 部分。

Starters

Starters 是一组方便的依赖描述符,你可以将它们包含在你的应用程序中。 你可以一站式获取所有需要的 Spring 和相关技术,而不必在示例代码中查找和复制粘贴大量的依赖描述符。 例如,如果你想开始使用 Spring 和 JPA 进行数据库访问,请在项目中包含 spring-boot-starter-data-jpa 依赖。

Starters 包含了许多你需要快速启动和运行项目的依赖项,并提供了一组一致的、受管理的传递依赖项。

What is in a name

所有官方 starters 都遵循类似的命名模式:spring-boot-starter-*,其中 * 是特定类型的应用程序。 这种命名结构旨在帮助你找到 starter。 许多 IDE 中的 Maven 集成允许你按名称搜索依赖项。 例如,安装了适当的 Eclipse 或 Spring Tools 插件后,你可以在 POM 编辑器中按 ctrl-space 并输入 “spring-boot-starter” 以获取完整列表。

创建自己的 Starter 部分所述,第三方 starters 不应以 spring-boot 开头,因为它保留给官方 Spring Boot 构件。 相反,第三方 starter 通常以项目名称开头。 例如,一个名为 thirdpartyproject 的第三方 starter 项目通常会被命名为 thirdpartyproject-spring-boot-starter

以下应用程序 starters 由 Spring Boot 在 org.springframework.boot 组下提供:

Table 1. Spring Boot application starters
Name Description

spring-boot-starter

Core starter, including auto-configuration support, logging and YAML

spring-boot-starter-activemq

Starter for JMS messaging using Apache ActiveMQ

spring-boot-starter-amqp

Starter for using Spring AMQP and Rabbit MQ

spring-boot-starter-aop

Starter for aspect-oriented programming with Spring AOP and AspectJ

spring-boot-starter-artemis

Starter for JMS messaging using Apache Artemis

spring-boot-starter-batch

Starter for using Spring Batch

spring-boot-starter-cache

Starter for using Spring Framework’s caching support

spring-boot-starter-data-cassandra

Starter for using Cassandra distributed database and Spring Data Cassandra

spring-boot-starter-data-cassandra-reactive

Starter for using Cassandra distributed database and Spring Data Cassandra Reactive

spring-boot-starter-data-couchbase

Starter for using Couchbase document-oriented database and Spring Data Couchbase

spring-boot-starter-data-couchbase-reactive

Starter for using Couchbase document-oriented database and Spring Data Couchbase Reactive

spring-boot-starter-data-elasticsearch

Starter for using Elasticsearch search and analytics engine and Spring Data Elasticsearch

spring-boot-starter-data-jdbc

Starter for using Spring Data JDBC

spring-boot-starter-data-jpa

Starter for using Spring Data JPA with Hibernate

spring-boot-starter-data-ldap

Starter for using Spring Data LDAP

spring-boot-starter-data-mongodb

Starter for using MongoDB document-oriented database and Spring Data MongoDB

spring-boot-starter-data-mongodb-reactive

Starter for using MongoDB document-oriented database and Spring Data MongoDB Reactive

spring-boot-starter-data-neo4j

Starter for using Neo4j graph database and Spring Data Neo4j

spring-boot-starter-data-r2dbc

Starter for using Spring Data R2DBC

spring-boot-starter-data-redis

Starter for using Redis key-value data store with Spring Data Redis and the Lettuce client

spring-boot-starter-data-redis-reactive

Starter for using Redis key-value data store with Spring Data Redis reactive and the Lettuce client

spring-boot-starter-data-rest

Starter for exposing Spring Data repositories over REST using Spring Data REST and Spring MVC

spring-boot-starter-freemarker

Starter for building MVC web applications using FreeMarker views

spring-boot-starter-graphql

Starter for building GraphQL applications with Spring GraphQL

spring-boot-starter-groovy-templates

Starter for building MVC web applications using Groovy Templates views

spring-boot-starter-hateoas

Starter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS

spring-boot-starter-integration

Starter for using Spring Integration

spring-boot-starter-jdbc

Starter for using JDBC with the HikariCP connection pool

spring-boot-starter-jersey

Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web

spring-boot-starter-jooq

Starter for using jOOQ to access SQL databases with JDBC. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc

spring-boot-starter-json

Starter for reading and writing json

spring-boot-starter-mail

Starter for using Java Mail and Spring Framework’s email sending support

spring-boot-starter-mustache

Starter for building web applications using Mustache views

spring-boot-starter-oauth2-authorization-server

Starter for using Spring Authorization Server features

spring-boot-starter-oauth2-client

Starter for using Spring Security’s OAuth2/OpenID Connect client features

spring-boot-starter-oauth2-resource-server

Starter for using Spring Security’s OAuth2 resource server features

spring-boot-starter-pulsar

Starter for using Spring for Apache Pulsar

spring-boot-starter-pulsar-reactive

Starter for using Spring for Apache Pulsar Reactive

spring-boot-starter-quartz

Starter for using the Quartz scheduler

spring-boot-starter-rsocket

Starter for building RSocket clients and servers

spring-boot-starter-security

Starter for using Spring Security

spring-boot-starter-test

Starter for testing Spring Boot applications with libraries including JUnit Jupiter, Hamcrest and Mockito

spring-boot-starter-thymeleaf

Starter for building MVC web applications using Thymeleaf views

spring-boot-starter-validation

Starter for using Java Bean Validation with Hibernate Validator

spring-boot-starter-web

Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container

spring-boot-starter-web-services

Starter for using Spring Web Services

spring-boot-starter-webflux

Starter for building WebFlux applications using Spring Framework’s Reactive Web support

spring-boot-starter-websocket

Starter for building WebSocket applications using Spring Framework’s MVC WebSocket support

除了应用程序 starters 之外,以下 starters 可用于添加 生产就绪 功能:

Table 2. Spring Boot production starters
Name Description

spring-boot-starter-actuator

Starter for using Spring Boot’s Actuator which provides production ready features to help you monitor and manage your application

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

Table 3. Spring Boot technical starters
Name Description

spring-boot-starter-jetty

Starter for using Jetty as the embedded servlet container. An alternative to spring-boot-starter-tomcat

spring-boot-starter-log4j2

Starter for using Log4j2 for logging. An alternative to spring-boot-starter-logging

spring-boot-starter-logging

Starter for logging using Logback. Default logging starter

spring-boot-starter-reactor-netty

Starter for using Reactor Netty as the embedded reactive HTTP server.

spring-boot-starter-tomcat

Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web

spring-boot-starter-undertow

Starter for using Undertow as the embedded servlet container. An alternative to spring-boot-starter-tomcat

要了解如何交换技术方面,请参阅有关 交换 Web 服务器日志系统 的 how-to 文档。

有关其他社区贡献的 starters 列表,请参阅 GitHub 上 spring-boot-starters 模块中的 README 文件