强烈建议您选择一个构建系统,它支持依赖关系管理并且可以使用被发布到“ Maven Central(Maven中心库)”存储库的归档。我们建议您选择Maven或Gradle。Spring Boot与其他构建系统(例如,Ant)一起使用也是存在可能的,但是它们并没有得到很好的支持。
1.1 依赖管理
每个Spring Boot的发布版本都提供了它所支持的依赖的精选列表。实际上,您不需要为构建配置中的所有依赖项提供版本,因为Spring Boot会为您管理版本。当您升级Spring Boot本身时,这些依赖项也会以一致的方式升级。
在需要的时候,仍然可以指定版本覆盖Spring Boot的建议版本。
精选列表包含可与Spring Boot一起使用的所有Spring模块以及精炼的第三方库列表。该列表被提供作为一个标准的材料清单(spring-boot-dependencies
),它可与Maven和Gradle一起使用。
每个Spring Boot版本都与一个Spring Framework的基本版本相关联。我们强烈建议您不要指定其版本。
1.2 Maven
要了解有关将Spring Boot与Maven结合使用的信息,请参阅Spring Boot的Maven插件的文档:
- 参考文档(HTML和PDF)
-
1.3 Gradle
要了解有关将Spring Boot与Gradle结合使用的信息,请参阅Spring Boot的Gradle插件的文档:
- API
1.4 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="2.4.0-SNAPSHOT" />
<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),请参见howto.html “操作方法”。
1.5 启动器(Starters)
启动器是一组便捷的依赖项描述符,您可以在应用程序中引入它们。您可以一站式获得所需的所有Spring和相关技术,而不必遍历示例代码和复制粘贴大量依赖描述符。例如,如果要开始使用Spring和JPA进行数据库访问,请在项目中引入spring-boot-starter-data-jpa
依赖项。
启动器包含许多启动项目并快速运行所需的依赖项,并且具有一组一致的受支持的托管传递性依赖项。
名字里面包含什么 所有官方启动器都遵循类似的命名方式:
spring-boot-starter-*
,其中*
是特定类型的应用程序。这种命名结构旨在在您需要寻找启动器时提供帮助。许多IDE中的Maven集成使您可以按名称搜索依赖项。例如,在安装了适当的Eclipse或STS插件的情况下,您可以在POM编辑器中按ctrl-space
,然后键入“ spring-boot-starter”以获取完整列表。 如“创建您自己的启动程序”部分中所述,第三方启动程序不应以开头spring-boot
,因为它是Spring Boot官方归档的保留模式。相对比,第三方启动程序通常以项目名称开头。例如,一个名为thirdpartyproject
的第三方启动程序项目通常将名为thirdpartyproject-spring-boot-starter
。
Spring Boot在org.springframework.boot
组下提供了以下应用程序启动器:
表1. Spring Boot应用程序启动器
名称 | 描述 |
---|---|
spring-boot-starter |
核心启动器,包括自动配置支持、日志记录和YAML |
spring-boot-starter-activemq |
使用Apache ActiveMQ进行JMS消息传递的启动器 |
spring-boot-starter-amqp |
使用Spring AMQP和Rabbit MQ的启动器 |
spring-boot-starter-aop |
使用Spring AOP和AspectJ进行面向方面编程的启动器 |
spring-boot-starter-artemis |
使用Apache Artemis进行JMS消息传递的启动器 |
spring-boot-starter-batch |
使用Spring Batch的启动器 |
spring-boot-starter-cache |
使用Spring Framework的缓存支持的启动器 |
spring-boot-starter-data-cassandra |
使用Cassandra分布式数据库和Spring Data Cassandra的启动器 |
spring-boot-starter-data-cassandra-reactive |
使用Cassandra分布式数据库和Spring Data Cassandra Reactive的启动器 |
spring-boot-starter-data-couchbase |
使用Couchbase面向文档的数据库和Spring Data Couchbase的启动器 |
spring-boot-starter-data-couchbase-reactive |
使用Couchbase面向文档的数据库和Spring Data Couchbase Reactive的启动器 |
spring-boot-starter-data-elasticsearch |
使用Elasticsearch搜索和分析引擎以及Spring Data Elasticsearch的启动器 |
spring-boot-starter-data-jdbc |
使用Spring Data JDBC的启动器 |
spring-boot-starter-data-jpa |
将Spring Data JPA与Hibernate结合使用的启动器 |
spring-boot-starter-data-ldap |
使用Spring Data LDAP的启动器 |
spring-boot-starter-data-mongodb |
使用MongoDB面向文档的数据库和Spring Data MongoDB的启动器 |
spring-boot-starter-data-mongodb-reactive |
使用MongoDB面向文档的数据库和Spring Data MongoDB Reactive的启动器 |
spring-boot-starter-data-neo4j |
使用Neo4j图形数据库和Spring Data Neo4j的启动器 |
spring-boot-starter-data-r2dbc |
使用Spring Data R2DBC的启动器 |
spring-boot-starter-data-redis |
使用Redis键值数据存储与Spring Data Redis和Lettuce客户端的启动器 |
spring-boot-starter-data-redis-reactive |
将Redis键值数据存储与Spring Data Redis Reactive和Lettuce客户端一起使用的启动器 |
spring-boot-starter-data-rest |
通过REST(使用Spring Data REST)暴露Spring Data存储库的启动器 |
spring-boot-starter-data-solr |
将Apache Solr搜索平台与Spring Data Solr结合使用的启动器 |
spring-boot-starter-freemarker |
使用FreeMarker视图构建MVC Web应用程序的启动器 |
spring-boot-starter-groovy-templates |
使用Groovy模板视图构建MVC Web应用程序的启动器 |
spring-boot-starter-hateoas |
使用Spring MVC和Spring HATEOAS构建基于超媒体的RESTful Web应用程序的启动器 |
spring-boot-starter-integration |
使用Spring Integration的启动器 |
spring-boot-starter-jdbc |
结合使用JDBC和HikariCP连接池的启动器 |
spring-boot-starter-jersey |
使用JAX-RS和Jersey构建RESTful Web应用程序的启动器。spring-boot-starter-web 的替代品 |
spring-boot-starter-jooq |
使用jOOQ访问SQL数据库的启动器。替代spring-boot-starter-data-jpa 或spring-boot-starter-jdbc |
spring-boot-starter-json |
读写JSON的启动器 |
spring-boot-starter-jta-atomikos |
使用Atomikos的JTA事务的启动器 |
spring-boot-starter-jta-bitronix |
使用Bitronix的JTA事务的启动器。从2.3.0版本起不推荐使用 |
spring-boot-starter-mail |
使用Java Mail和Spring Framework的电子邮件发送支持的启动器 |
spring-boot-starter-mustache |
使用Mustache视图构建Web应用程序的启动器 |
spring-boot-starter-oauth2-client |
使用Spring Security的OAuth2/OpenID Connect客户端功能的启动器 |
spring-boot-starter-oauth2-resource-server |
使用Spring Security的OAuth2资源服务器功能的启动器 |
spring-boot-starter-quartz |
使用Quartz Scheduler的启动器 |
spring-boot-starter-rsocket |
用于构建RSocket客户端和服务器的启动器 |
spring-boot-starter-security |
使用Spring Security的启动器 |
spring-boot-starter-test |
将包括JUnit Jupiter、Hamcrest和Mockito在内的库用于测试Spring Boot应用程序的启动器 |
spring-boot-starter-thymeleaf |
使用Thymeleaf视图构建MVC Web应用程序的启动器 |
spring-boot-starter-validation |
通过Hibernate Validator使用Java Bean验证的启动器 |
spring-boot-starter-web |
使用Spring MVC构建Web(包括RESTful)应用程序的启动器。 使用Tomcat作为默认的嵌入式容器 |
spring-boot-starter-web-services |
使用Spring Web Services的启动器 |
spring-boot-starter-webflux |
使用Spring Framework的Reactive Web支持构建WebFlux应用程序的启动器 |
spring-boot-starter-websocket |
使用Spring Framework的WebSocket支持构建WebSocket应用程序的启动器 |
除了应用程序启动程序,以下启动器可用于添加生产就绪功能:
表2. Spring Boot生产入门
名称 | 描述 |
---|---|
spring-boot-starter-actuator |
使用Spring Boot的Actuator的启动器,它提供了生产就绪功能,可帮助您监视和管理应用程序 |
最后,Spring Boot还包括以下启动器,如果您要排除或更换特定的技术,可以使用这些启动器:
表3. Spring Boot技术入门
名称 | 描述 |
---|---|
spring-boot-starter-jetty |
使用Jetty作为嵌入式servlet容器的启动器。是spring-boot-starter-tomcat 的替代品 |
spring-boot-starter-log4j2 |
使用Log4j2进行日志记录的启动器。是spring-boot-starter-logging 的替代品 |
spring-boot-starter-logging |
使用Logback进行日志记录的启动器。默认日志记录启动器 |
spring-boot-starter-reactor-netty |
使用Reactor Netty作为嵌入式反应式HTTP服务器的启动器 |
spring-boot-starter-tomcat |
将Tomcat用作嵌入式servlet容器的启动器。spring-boot-starter-web 默认使用的servlet容器 |
spring-boot-starter-undertow |
使用Undertow作为嵌入式servlet容器的启动器。spring-boot-starter-tomcat 的替代品 |
要了解如何更换技术的信息,请参阅有关更换Web服务器和日志记录系统的方法文档。
有关社区贡献的其他启动器的列表,请参阅GitHub中
spring-boot-starters
模块的README文件。