Unresolved directive in v2.3.adoc - include::attributes.adoc[] :root-docs: https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE :docs: {root-docs}/reference/html :gradle-docs: {root-docs}/gradle-plugin/reference/html :maven-docs: {root-docs}/maven-plugin/reference/html

环境

  • Gradle 6.3+ (if you are building with Gradle). 5.6.x is also supported but in a deprecated form.

  • Jetty 9.4.22+ (if you are using Jetty as the embedded container)

  • jdk8+, jdk11, jdk14

重大变更

Validation Starter 不再包含在web starters 中

参阅issue: #19550, 默认情况下,Web和WebFlux启动器不再依赖于验证启动器.
如果应用程序正在使用验证功能, 例如你发现 javax.validation.* 导入未被解析, 你需要自己加一个启动器.

For Maven builds:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

For Gradle:

dependencies {
  ...
  implementation 'org.springframework.boot:spring-boot-starter-validation'
}

Spring Data Neumann

springboot2.3附带了Spring data的主要版本.
如果您正在使用Cassandra、Couchbase、Elasticsearch、MongoDB或JDBC,则需要格小心。

Cassandra

这个版本切换到cassandrav4,它带来了许多向后不兼容的变化。
如果您依赖 ClusterBuilderCustomizer 自定义 Cluster ,则此概念在v4中已不存在,并已被两个更具体的自定义程序所取代:

  • DriverConfigLoaderBuilderCustomizer 自定义驱动程序的属性。 Please use this for any property that is not exposed yet请将此用于尚未公开的任何属性.

  • CqlSessionBuilderCustomizer 自定义 CqlSession (former Session).

The Cassandra v4 driver no longer has automatic local DC inference from contact points. 因此, the "local-datacenter" 必须使用默认负载平衡策略设置属性,并且contact points 必须位于该数据中心。 添加了一个新的 spring.data.cassandra.local datacenter 属性,可以方便地设置本地数据中心。

Couchbase

此版本切换到Couchbase sdkv3,它带来了许多向后不兼容的更改.

  • To connect to a cluster, you should now use spring.couchbase.connection-string instead of the former spring.couchbase.bootstrap-hosts.

  • Role-based access controls have now been generalized.

  • Spring Boot no longer auto-configures a Bucket but you can easily do so using the Cluster API.

  • Endpoints IO configuration has been harmonized in spring.couchbase.env.io.

  • If you were extending CouchbaseConfiguration to customize the environment, please use ClusterEnvironmentBuilderCustomizer to do so in a more idiomatic fashion.

A bucket name needs to be provided if you’re using Couchbase with Spring Data.

Elasticsearch

不推荐使用的 Native Elasticsearch transport 已被删除,因为Elasticsearch和Spring data 它们在其下一版本中都不支持它。

对Jest库的支持在这个版本中也被删除了。

Spring Boot现在默认使用Elasticsearch 7.5+。

MongoDB

这个版本切换到mongodb4,并适配 reactive 和 imperative drivers。

如果你用的是starter,这对你来说应该是相当透明的。

一个显著的变化是`MongoClientSettingsBuilderCustomizer` beans 现在在使用imperative drivers时被应用.+

以前它们只适用于reactive情况。

通过这些适配,如果你使用 spring-boot-starter-data-mongodb-reactive 非 reactive infrastructure 不再提供 .
如果您需要在启动时使用imperative infrastructure (e.g. MongoOperations), 请考虑添加 `spring-boot-starter-data-mongodb`依赖.

Neo4j

The open session in view interceptor for Neo4j is now disabled by default. If you need to enable it again, use the standard spring.data.neo4j.open-in-view property.

The details of the Neo4j health indicator now contains the version and edition of the server, as shown in the following example:

neo4j: {
  status: "UP",
  details: {
    edition: "community",
    version: "4.0.0"
  }
}

JDBC

Among its new features, Spring Data JDBC 2.0 now quotes identifiers by default. This behaviour can be disabled by calling setForceQuote(false) on the RelationalMappingContext.

Micrometer

此版本升级到Millimeter 1.5,这带来了许多不推荐的情况:

  • Service Level Agreements 被重命名为 Service Level Objectives,边界表示为 double 而不是 long.

  • Wavefront metrics 现在通过 WavefrontSender 来暴露. 因此,读取和连接超时属性不再有效。

Jackson

此版本升级到jackson2.11,其中包括对 java.util.Date and java.util.Calendar 默认格式的更改. 请参阅 FasterXML/jackson-databind#2643

Spring Cloud Connectors starter 被移除

Spring Cloud Connectors starter deprecated in 2.2 in favor of Java CFEnv. 这个 starter 已删除, Spring Cloud Connectors 依赖项不再包含在Spring Boot的托管依赖项中.

内置 Servlet web server 线程配置

用于配置嵌入式Servlet web服务器使用的线程的配置属性 (Jetty, Tomcat, and Undertow) 已转移到专用的 threads 组.
这些属性目前可以在 server.jetty.threads, server.tomcat.threads, and server.undertow.threads 中找到.
旧属性保留为不推荐使用的形式,以便于迁移。

对默认错误页内容的更改

默认情况下,错误消息和任何绑定错误不再包含在默认错误页中。 这降低了向客户泄露信息的风险。 server.error.include-message and server.error.include-binding-errors 可以用来分别控制消息的包含和绑定错误. 支持的值为 always, on-param, and never.

磁盘空间运行状况指示器

The auto-configured disk space health indicator no longer requires the path that is monitored to exist when the application starts. A non-existent path will be detected as having zero usable space resulting in a down response from the indicator.

developmentOnly Gradle configuration 的自动创建

The developmentOnly 配置主要用于在springboot的DevTools上声明依赖关系,现在由springboot的Gradle插件自动创建. 任何 developmentOnly 的手动配置都应该从Gradle脚本中删除,因为它的存在将导致build 失败,并显示消息 cannot add a configuration with name“developmentOnly ,因为该名称的配置已经存在`

移除Maven Site Plugin management

Spring Boot’s 构建 不再使用 site plugin (maven-site-plugin) 并且它的插件管理已被删除. 如果你依赖 Spring Boot 的版本管理,你应该添加你自己的插件管理.

移除 Maven Exec Plugin 自定义配置

如果你继承自 spring-boot-starter-parent, 它不用再配置 Maven’s exec plugin (exec-maven-plugin) 用 start-class 去设置 main class . 如果你依赖那个, 您可以按如下方式恢复该行为:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <configuration>
       <mainClass>${start-class}</mainClass>
   </configuration>
</plugin>

ApplicationContextRunner 默认禁用 bean overriding

为了与`SpringApplication`保持一致, ApplicationContextRunner 现在默认禁用 bean 覆盖.
如果您需要使用 bean 覆盖进行测试, withAllowBeanDefinitionOverriding 可以用来启用它.

激活多个配置文件 @ActiveProfiles

@ActiveProfiles 注释现在支持包含逗号的配置文件名称.
这意味着像 @ActiveProfiles("p1,p2") 这样的注释会将提供的值 p1,p2 视为单个名称的配置文件。
要激活多个配置文件,请将每个配置文件名称作为单独的值提供,如`@ActiveProfiles({"p1","p2"})`。

WebServerInitializedEvent and ContextRefreshedEvent

作为引入对 graceful shutdown 支持的一部分,Web 服务器初始化现在在应用程序上下文刷新处理结束时执行,而不是在刷新处理完成后立即执行. 因此,WebServerInitializedEvent 现在在 ContextRefreshedEvent 之前发布。

Spring Boot 2.2 的弃用

Spring Boot 2.2 中弃用的大多数类、方法和属性已在此版本中删除。
请确保在升级之前您没有调用已弃用的方法。

Configuration properties

许多属性已被重命名或弃用。您可以使用 spring-boot-properties-migrator 模块来识别这些属性。
一旦作为依赖项添加到您的项目中,这不仅会在启动时分析您的应用程序环境并打印诊断信息,还会在运行时为您临时迁移属性。

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-properties-migrator</artifactId>
	<scope>runtime</scope>
</dependency>
runtime("org.springframework.boot:spring-boot-properties-migrator")
完成迁移后,请确保从项目的依赖项中删除此模块。

Java 14 support

Spring Boot 2.3 添加了对 Java 14 的支持。也支持 Java 8 和 11。

通过 Cloud Native Buildpacks 构建 OCI 镜像

支持通过使用 Cloud Native Buildpacks的方式 {docs}/spring-boot-features.html#building-docker-images[构建docker镜像] 并已通过以下方式添加到 Maven 和 Gradle 插件中 {maven-docs}/#build-image[spring-boot:build-image goal] , {maven-docs}/#build-image[bootBuildImage task]. Paketo 默认情况下使用 Java buildpack 来创建镜像.

构建jar 层以包含在 Docker 映像中

对构建内容分层的 jar 文件的支持已添加到 {maven-docs}/#repackage-layers[Maven] 和 {gradle-docs}/#packaging-layered-jars[Gradle] plugins.
分层根据 jar 内容的更改频率将它们分离。
这种分离允许构建更高效的 Docker 镜像。
未更改的现有 分层可以重复使用,并将已更改的分层放置在顶部。

根据您的应用程序,您可能希望调整分层的创建方式并添加新分层。
这可以使用如何将 jar 分成层以及这些层的顺序的描述的配置来完成。

创建 jar 分层时, 默认情况下, spring-boot-jarmode-layertools jar 将作为依赖项添加到您的 jar 中(这可以通过构建配置禁用).
使用类路径上的这个 jar,您可以在特殊模式下启动您的应用程序,该模式允许引导代码运行与您的应用程序完全不同的内容,例如,提取分层里的的内容。
要查看可用选项,请使用 -Djarmode=layertools 启动一个 fat jar,如下例所示:

$ java -Djarmode=layertools -jar my-app.jar
Usage:
  java -Djarmode=layertools -jar my-app.jar

Available commands:
  list     List layers from the jar that can be extracted
  extract  Extracts layers from the jar for image creation
  help     Help about any command

分解 Fat jar 时可预测的类路径排序

使用 Maven 和 Gradle 构建的 Fat jars 现在包含一个索引文件。
jar 分解时,这个索引文件是用来保证classpath 的顺序和直接执行jar 时一样的。

支持配置文件的通配符位置

Spring Boot 现在在加载配置文件时支持通配符位置。
默认情况下,支持 jar 外部的 config/*/ 通配符位置。
当有多个配置属性源时,这在 Kubernetes 等环境中很有用。 例如,如果你有单独的 mysql 和 redis 配置,如果你把它们放在 config 中,即 config/mysql/application.propertiesconfig/redis/application.properties,它们可以被自动选择。

优雅停止

所有四个嵌入式 Web 服务器都支持优雅停止 (Jetty, Reactor Netty, Tomcat, and Undertow) 以及反应式和基于 Servlet 的 Web 应用程序.
启用时使用 server.shutdown=graceful, 关机时, Web 服务器将不再允许新请求并且将等待关机期间的请求完成.可以使用配置 spring.lifecycle.timeout-per-shutdown-phase 来配置这个等待时间.参阅 {docs}/spring-boot-features.html#boot-features-graceful-shutdown[优雅关机] 获取更多详情

Liveness, Readiness 探针

Spring Boot 现在内置了关于应用程序可用性的知识,跟踪它是否处于活动状态以及是否准备好处理流量。 health endpoint can be configured to expose the liveness (/actuator/health/liveness) and readiness (/actuator/health/readiness) of you application with the management.health.probes.enabled=true configuration property. 在 Kubernetes 上运行时,这是自动完成的。

要了解有关此功能的更多信息,请查看 liveness-and-readiness-probes-with-spring-boot以及它链接到的参考文档.

Spring Data Neumann

Spring Boot 2.3 附带一个 Spring Data 的 major 版本。请参阅 Spring Data Neumann goes GA 了解更多。

R2DBC support

当 r2dbc 在类路径上时,ConnectionFactory 自动配置为与 jdbc`DataSource` 类似的安排。
如果 Spring Data 在类路径上,存储库也会像往常一样自动配置。

R2DBC 支持还为连接工厂添加了一个健康指标、ConnectionPool 的指标和一个测试切片`@DataR2dbcTest`。

WebFlux 应用程序的可配置基本路径

现在可以配置 WebFlux 应用程序的所有 Web 处理程序的基本路径。使用 spring.webflux.base-path 属性来做到这一点。

Web 应用程序中的date-time转换

Web 应用程序中时间和日期时间值的转换现在可以通过 application properties 进行配置。
这补充了对格式化日期值的现有支持。
mvc 中 , properties 分别是 spring.mvc.format.time, spring.mvc.format.date-time .
WebFlux 中, properties 分别是 spring.webflux.format.time and spring.webflux.format.date-time .

除了采取典型的格式化模式, 用于配置dates, times, date-times格式的属性现在支持值`iso`.
设置后,将应用相应的ISO-8601格式。
以下属性支持 iso 值:

  • spring.mvc.format.date

  • spring.mvc.format.date-time

  • spring.mvc.format.time

  • spring.webflux.format.date

  • spring.webflux.format.date-time

  • spring.webflux.format.time

Actuator 改进

配置属性的端到端跟踪

截至 #17886, /actuator/configprops endpoint 提供有关配置属性的端到端信息,使其行为与环境 endpoint保持一致 .
例如,添加 server.server-header=Spring Bootapplication.properties 中, endpoint 将向您展示以下内容:

"serverHeader": {
  "origin": "class path resource [application.properties]:2:22",
  "value": "Spring Boot"
},

metrics endpoint 的名词将按字母排序

actuator/metrics 中可用的度量名称现在按字母顺序排列,这样更容易找到您要查找的内容。

Query-less datasource health indicator

在没有验证查询的情况下, HealthIndicator 数据源将处于 query-less mode, 使用 java.sql.Connection#isValid 验证其连接.

为webmvc和WebFlux度量提供额外的tag

除了默认情况下为MVC和WebFlux提供的tag之外,还可以使用其他tag。
对于MVC,可以使用 WebMvcTagsContributor @Bean,对于WebFlux 使用 WebFluxTagsContributor @Bean`进行贡献。

Wavefront’s Sender 自动配置

Wavefront的自动配置已更新为定义一个 WavefrontSender bean。
这允许在单个连接上发布Wavefront的度量和轨迹。

Native Kafka metrics

Kafka度量是为自动配置的 ConsumerFactoryProducerFactory 创建的消费者和生产者本地发布的。 要为自定义工厂创建的组件生成度量,应添加侦听器,如以下示例所示:

factory.addListener(new MicrometerConsumerListener<>(meterRegistry));
如果您启用JMX支持的唯一目的是收集Kafka度量,则不再需要这样做。

RSocket 对 Spring Integration 的支持

springboot现在为Spring Integration的RSocket支持提供了自动配置。

如果 spring-integration-rsocket 为可用的, 开发人员可以使用 "spring.rsocket.server.*" properties 并且 让它使用 IntegrationRSocketEndpoint or RSocketOutboundGateway 组件去处理 RSocket 消息.

绑定到 Period

如果一个属性需要表达一段时间,你可以使用`java.time.Period` 属性来实现。
Duration 支持类似,支持一种简单的格式(比如使用10w表达10周)在元数据配置也支持这样做。

Web服务切片测试

添加了注释 @WebServiceClientTest 以支持Web服务的“切片”测试。

依赖项升级

springboot2.3迁移到几个Spring项目的新版本:

  • Spring Data Neumann

  • Spring HATEOAS 1.1

  • Spring Integration 5.3

  • Spring Kafka 2.5

  • Spring Security 5.3

  • Spring Session Dragonfruit

spring boot 2.3构建的Spring框架和Reactor生成与 spring boot 2.2相同。

许多第三方依赖项也已更新,其中一些更值得注意的是:

  • Artemis 2.12

  • AssertJ 3.16

  • Cassandra Driver 4.6

  • Couchbase Client 3.0

  • Elasticsearch 7.6

  • Flyway 6.4

  • Hibernate Validator 6.1

  • Infinispan 10.1

  • Jackson 2.11

  • JUnit Jupiter 5.6

  • Kafka 2.5

  • Kotlin 1.3.72

  • Lettuce 5.3

  • Micrometer 1.5

  • Mockito 3.3

  • MongoDB 4.0

  • QueryDSL 4.3

其他

除了上面列出的更改之外,还有许多小的调整和改进,包括:

  • 在我们的JPA支持中更新了配置默认值,以改进测试体验, see #16230 , #16747.

  • spring-boot-autoconfigure-processor 的输出现在是可重复的,这使得它在Gradle的构建缓存中工作得更好.

  • Couchbase的类型键可以通过`spring.data.Couchbase.type-key配置`.

  • OAuth2参数绑定现在可与 @WebMvcTest 一起使用`.

  • Jetty的后备队列可以使用`server.Jetty.max-queue-capacity’配置`.

  • Liquibase的tag支持可以使用`spring.Liquibase.tag配置`.现在可以通过 spring.liquibase.clear-checksums 属性清除当前变更日志中的所有校验。

  • Gradle元数据现在已发布.

  • DataSourceBuilder 可以被配置为 SimpleDriverDataSource.

  • `DataSource`metrics现在有了一个描述。

  • 可以使用 spring.main.cloud-platform 覆盖云平台的自动检测。

  • 当请求具有principal时,现在支持来自启动器的HTTP端点的响应缓存。

  • Maven 对创建 fat jar 的支持现在遵从 project.build.outputTimestamp 属性,允许其输出可重现 reproducible.

  • The Javadoc 的 Maven plugin is {root-docs}/maven-plugin/api/[now published].

  • 自定义接口, RSocketMessageHandlerCustomizer,用于自定义自动配置的`RSocketMessageHandler`,

  • 自定义接口, DefaultCookieSerializerCustomizer, 用于自定义自动配置的 DefaultCookieSerializer.

  • 自动配置默认servlet 现在可以通过设置 server.servlet.register-default-servletfalse 来禁用.

  • 新的条件, @ConditionalOnWarDeployment 已经添加 它可用于检测应用程序何时已作为war部署到Servlet容器或应用程序服务器。

  • properties migrator处理所有不推荐使用的属性,而不仅仅是那些具有错误级别的属性。

  • 当销毁war的ServletContext时,JDBC驱动程序被取消注册。

  • Redis的sentinel密码可以使用 spring.redis.sentinel.password 进行配置。

SpringBoot2.3中的弃用

  • spring.http. 属性已移动到 server.servlet.encoding., spring.mvc. and spring.codec., 参阅 #18827.

  • SpringApplication#refresh(ApplicationContext) 已被弃用而取代他的是 SpringApplication#refresh(ConfigurableApplicationContext).

  • ON_TRACE_PARAM 用于 server.error.include-stacktrace 属性已重命名为 ON_PARAM.

  • org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientBuilderCustomizer 已被弃用而取代他的是 org.springframework.boot.autoconfigure.elasticsearch.RestClientBuilderCustomizer

New and Noteworthy

参阅 Configuration properties change between 2.3.6.RELEASE and 2.4.0 查看有关配置更改的完整概述。