Build Systems选择建议

强烈建议选择支持依赖关系管理的构建系统,建议您选择Maven或Gradle。Spring Boot与可以与其他构建系统(例如Ant)一起工作,但它们并没有得到特别好的支持。

依赖关系管理

Spring Boot的每个版本都提供了默认支持的依赖列表(包含可以与Spring Boot一起使用的所有spring模块以及其他第三方库类库。)。并且不需要在pom.xml文件中提供这些默认依赖项的版本,因为Spring Boot会自动管理这些依赖。当您升级Spring Boot时,这些依赖的版本也会升级到与Spring Boot一致的版本。

TIPS:如果需要,可以指定版本号来并覆盖Spring Boot的默认版本。(每个版本的Spring Boot都与Spring Framework的基本版本相关联,不建议更改Spring Framework的版本好)

Maven

Maven 可通过继承spring-boot-starter-parent 来构建spring boot项目并获取一些默认值.

  • JDK默认版本为JDK1.8
  • 编码字符集为:UTF-8
  • 继承 spring-boot-dependencies 的依赖,用可于管理公共依赖的版本。此依赖管理允许在pom文件中省略这些依赖项的标记
  • 合理的资源过滤

TIPS:yml文件接受Spring样式的占位符(${…}),Maven过滤改为使用@…@占位符。(您可以通过设置Maven属性resource.delimiter来覆盖它。)

通过继承spring-boot-starter-parent使用spring-boot

<parent> 
	<groupId> org.springframework.boot </ groupId> 
	<artifactId> spring-boot-starter-parent </ artifactId> 
	<version> 2.1.6.RELEASE < / version> 
</ parent>

不通过继承spring-boot-starter-parent使用spring-boot

不是每个人都喜欢继承spring-boot-starter-parent。比如可能需要继承本公司的父依赖,或者想明确声明所有Maven配置。

如果您不想继承spring-boot-starter-parent,可以通过使用scope=import依赖项来保持依赖管理的好处 ,如下所示:

<dependencyManagement>
	<dependencies>
		<dependency>
			<!-- Import dependency management from Spring Boot -->
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-dependencies</artifactId>
			<version>2.1.6.RELEASE</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

通过dependencyManagement继承和通过parent继承的区别:

  • parent(全部继承)spring-boot-starter-parent时项目中没有引用的依赖,仍然会从父项目中继承该依赖项。
  • dependencyManagement只声明依赖,并不实现引入,只有在子项目中引入该依赖项,并且没有指定具体版本时,才会从父项目中继承该项,version和scope都读取自父pom。另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。

使用Spring Boot Maven插件

Spring Boot包含一个Maven插件,可以将项目打包为可执行jar。如果要使用它,请将插件添加到pom中,如以下示例所示:

<build> 
	<plugins> 
		<plugin> 
			<groupId> org.springframework.boot </ groupId> 
			<artifactId> spring-boot-maven-plugin </ artifactId> 
		</ plugin> 
	</ plugins> 
</ build>

Gradle

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

Spring Boot application starters

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-cloud-connectors

使用Spring Cloud Connectors的基础依赖简化了Cloud Foundry和Heroku等云平台中的服务连接

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-redis

在Spring Data Redis和Lettuce客户端上使用Redis键值数据存储的基础依赖

spring-boot-starter-data-redis-reactive

使用带有Spring Data Redis被动的Redis键值数据存储和Lettuce客户端的基础依赖

spring-boot-starter-data-rest

使用Spring Data REST通过REST公开Spring Data存储库的基础依赖

spring-boot-starter-data-solr

在Spring Data Solr中使用Apache 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事务的基础依赖

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调度程序的基础依赖

spring-boot-starter-security

使用Spring Security的基础依赖

spring-boot-starter-test

使用JUnit,Hamcrest和Mockito等库来测试Spring Boot应用程序的基础依赖

spring-boot-starter-thymeleaf

使用Thymeleaf视图构建MVC Web应用程序的基础依赖

spring-boot-starter-validation

使用Java Bean Validation和Hibernate Validator的基础依赖

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应用程序的基础依赖

spring-boot-starter-actuator

使用Spring Boot的Actuator的基础依赖,它提供生产就绪功能,帮助您监控和管理您的应用程序

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容器的基础依赖。使用的默认servlet容器启动器spring-boot-starter-web

spring-boot-starter-undertow

使用Undertow作为嵌入式servlet容器的基础依赖。替代spring-boot-starter-tomcat