建構系統

強烈建議您選擇支援依賴管理,並且可以取用發布到 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

若要了解如何將 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="3.3.5" />

	<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 模組,請參閱「操作指南」的從 Ant 建構可執行歸檔而不使用 spring-boot-antlib章節。

Starters

Starters 是一組方便的依賴描述符,您可以將其包含在您的應用程式中。 您可以一站式取得所有您需要的 Spring 和相關技術,而無需在範例程式碼中搜尋並複製貼上大量的依賴描述符。 例如,如果您想開始使用 Spring 和 JPA 進行資料庫存取,請在您的專案中包含 spring-boot-starter-data-jpa 依賴。

Starters 包含許多您需要的依賴,以便快速啟動並執行專案,並具有一致、受支援的受管理傳遞依賴集。

名稱的意義

所有官方 starters 都遵循類似的命名模式; spring-boot-starter-*,其中 * 是特定類型的應用程式。 此命名結構旨在協助您在需要尋找 starter 時。 許多 IDE 中的 Maven 整合可讓您依名稱搜尋依賴。 例如,在安裝適當的 Eclipse 或 Spring Tools 外掛程式後,您可以按 ctrl-space 在 POM 編輯器中輸入 "spring-boot-starter" 以取得完整清單。

建立您自己的 Starter章節中所述,第三方 starter 不應以 spring-boot 開頭,因為它是為官方 Spring Boot 成品保留的。 相反地,第三方 starter 通常以專案名稱開頭。 例如,名為 thirdpartyproject 的第三方 starter 專案通常會命名為 thirdpartyproject-spring-boot-starter

以下應用程式 starters 由 Spring Boot 在 org.springframework.boot 群組下提供

表 1. Spring Boot 應用程式 starters
名稱 描述

spring-boot-starter

核心 starter,包括自動組態支援、記錄和 YAML

spring-boot-starter-activemq

使用 Apache ActiveMQ 的 JMS 訊息傳遞 starter

spring-boot-starter-amqp

使用 Spring AMQP 和 Rabbit MQ 的 starter

spring-boot-starter-aop

使用 Spring AOP 和 AspectJ 的面向切面程式設計 starter

spring-boot-starter-artemis

使用 Apache Artemis 的 JMS 訊息傳遞 starter

spring-boot-starter-batch

使用 Spring Batch 的 starter

spring-boot-starter-cache

使用 Spring Framework 快取支援的 starter

spring-boot-starter-data-cassandra

使用 Cassandra 分散式資料庫和 Spring Data Cassandra 的 starter

spring-boot-starter-data-cassandra-reactive

使用 Cassandra 分散式資料庫和 Spring Data Cassandra Reactive 的 starter

spring-boot-starter-data-couchbase

使用 Couchbase 文件導向資料庫和 Spring Data Couchbase 的 starter

spring-boot-starter-data-couchbase-reactive

使用 Couchbase 文件導向資料庫和 Spring Data Couchbase Reactive 的 starter

spring-boot-starter-data-elasticsearch

使用 Elasticsearch 搜尋和分析引擎以及 Spring Data Elasticsearch 的 starter

spring-boot-starter-data-jdbc

使用 Spring Data JDBC 的 starter

spring-boot-starter-data-jpa

使用 Spring Data JPA 和 Hibernate 的 starter

spring-boot-starter-data-ldap

使用 Spring Data LDAP 的 starter

spring-boot-starter-data-mongodb

使用 MongoDB 文件導向資料庫和 Spring Data MongoDB 的 starter

spring-boot-starter-data-mongodb-reactive

使用 MongoDB 文件導向資料庫和 Spring Data MongoDB Reactive 的 starter

spring-boot-starter-data-neo4j

使用 Neo4j 圖形資料庫和 Spring Data Neo4j 的 starter

spring-boot-starter-data-r2dbc

使用 Spring Data R2DBC 的 starter

spring-boot-starter-data-redis

使用 Redis 鍵值資料儲存與 Spring Data Redis 和 Lettuce 客戶端的 starter

spring-boot-starter-data-redis-reactive

使用 Redis 鍵值資料儲存與 Spring Data Redis reactive 和 Lettuce 客戶端的 starter

spring-boot-starter-data-rest

使用 Spring Data REST 和 Spring MVC 透過 REST 公開 Spring Data 儲存庫的 starter

spring-boot-starter-freemarker

使用 FreeMarker 視圖建構 MVC 網路應用程式的 starter

spring-boot-starter-graphql

使用 Spring GraphQL 建構 GraphQL 應用程式的 starter

spring-boot-starter-groovy-templates

使用 Groovy Templates 視圖建構 MVC 網路應用程式的 starter

spring-boot-starter-hateoas

使用 Spring MVC 和 Spring HATEOAS 建構基於超媒體的 RESTful 網路應用程式的 starter

spring-boot-starter-integration

使用 Spring Integration 的 starter

spring-boot-starter-jdbc

使用 JDBC 和 HikariCP 連線池的 starter

spring-boot-starter-jersey

使用 JAX-RS 和 Jersey 建構 RESTful 網路應用程式的 starter。 spring-boot-starter-web 的替代方案

spring-boot-starter-jooq

使用 jOOQ 透過 JDBC 存取 SQL 資料庫的 starter。 spring-boot-starter-data-jpaspring-boot-starter-jdbc 的替代方案

spring-boot-starter-json

用於讀取和寫入 json 的 Starter

spring-boot-starter-mail

使用 Java Mail 和 Spring Framework 的電子郵件傳送支援的 starter

spring-boot-starter-mustache

使用 Mustache 視圖建構網路應用程式的 starter

spring-boot-starter-oauth2-authorization-server

使用 Spring Authorization Server 功能的 starter

spring-boot-starter-oauth2-client

使用 Spring Security 的 OAuth2/OpenID Connect 客戶端功能的 starter

spring-boot-starter-oauth2-resource-server

使用 Spring Security 的 OAuth2 資源伺服器功能的 starter

spring-boot-starter-pulsar

使用 Spring for Apache Pulsar 的 starter

spring-boot-starter-pulsar-reactive

使用 Spring for Apache Pulsar Reactive 的 starter

spring-boot-starter-quartz

使用 Quartz 排程器的 starter

spring-boot-starter-rsocket

建構 RSocket 客戶端和伺服器的 starter

spring-boot-starter-security

使用 Spring Security 的 starter

spring-boot-starter-test

使用包含 JUnit Jupiter、Hamcrest 和 Mockito 等函式庫的 starter 來測試 Spring Boot 應用程式

spring-boot-starter-thymeleaf

使用 Thymeleaf 視圖建構 MVC 網路應用程式的 starter

spring-boot-starter-validation

使用 Java Bean Validation 和 Hibernate Validator 的 starter

spring-boot-starter-web

使用 Spring MVC 建構網路(包括 RESTful)應用程式的 starter。 使用 Tomcat 作為預設嵌入式容器

spring-boot-starter-web-services

使用 Spring Web Services 的 starter

spring-boot-starter-webflux

使用 Spring Framework 的 Reactive Web 支援建構 WebFlux 應用程式的 starter

spring-boot-starter-websocket

使用 Spring Framework 的 MVC WebSocket 支援建構 WebSocket 應用程式的 starter

除了應用程式 starters 之外,以下 starters 可用於新增生產就緒功能

表 2. Spring Boot 生產 starters
名稱 描述

spring-boot-starter-actuator

使用 Spring Boot Actuator 的 starter,它提供生產就緒功能來協助您監控和管理您的應用程式

最後,如果您想排除或交換特定的技術層面,Spring Boot 也包含以下 starters

表 3. Spring Boot 技術 starters
名稱 描述

spring-boot-starter-jetty

使用 Jetty 作為嵌入式 servlet 容器的 starter。 spring-boot-starter-tomcat 的替代方案

spring-boot-starter-log4j2

使用 Log4j2 進行記錄的 starter。 spring-boot-starter-logging 的替代方案

spring-boot-starter-logging

使用 Logback 進行記錄的 starter。 預設記錄 starter

spring-boot-starter-reactor-netty

使用 Reactor Netty 作為嵌入式反應式 HTTP 伺服器的 starter。

spring-boot-starter-tomcat

使用 Tomcat 作為嵌入式 servlet 容器的 starter。 spring-boot-starter-web 使用的預設 servlet 容器 starter

spring-boot-starter-undertow

使用 Undertow 作為嵌入式 servlet 容器的 starter。 spring-boot-starter-tomcat 的替代方案

若要了解如何交換技術層面,請參閱有關交換網路伺服器記錄系統的操作文件。

如需其他社群貢獻的 starters 清單,請參閱 GitHub 上 spring-boot-starters 模組中的 README 檔案