Spring Boot 2.5 Release Notes

2022-09-22  本文已影响0人  侯文_ad82

本文主要参考官文文档。主要目的方便版本升级使用,对于需要升级部分进行翻译,对于新增特性等后续部分未做处理

1、 Upgrading from Spring Boot 2.4

1.1 SQL Script DataSource Initialization

在Spring Boot 2.5版本中,支持"schema.sql" 和"data.sql"的方法被重新设计了。DataSource 初始化,“spring.datasource." 属性已经弃用,取而代之的是新的"spring.sql.init。"属性。 这些属性还可以用于初始化通过R2DBC访问的SQL数据库。

schema.sqldata.sql 文件

在Spring Boot 2.5.1及以上版本中,新的SQL初始化属性支持检测JDBC和R2DBC的嵌入式数据源。默认情况下,SQL数据库初始化只在使用嵌入式内存数据库时执行。如果是非嵌入式数据库,要初始化一个SQL数据库,请设置“spring.sql.init.mode=always”;要禁用初始化,请设置“spring.sql.init.mode=never”。

单独凭证

新的基于的脚本的SQL数据库初始化不支持使用单独的凭据对结构(DDL)和数据(DML)更改。这降低了复杂性,并使其功能与Flyway和Liquibase保持一致。如果您需要为结构和数据初始化单独的凭证,请定义自己的bean(org.springframework.jdbc.datasource.init.DataSourceInitializer)。

Hibernate 和 data.sql

默认情况下,data.sql脚本在初始化Hibernate之前运行。这使基于脚本的基本初始化行为与Flyway和Liquibase的行为保持一致。如果你想使用data.sql作为schema被Hibernate创建,设置 spring.jpa.defer-datasource-initialization=true。虽然不建议混合使用数据库初始化技术,但这也允许也您使用schema.sql脚本在' data.sql '之前执行,在hibernate创建的schema之上构建。

初始化顺序

某些众所周知类型的bean(如JdbcOperations)将被排序,以便在数据库初始化之后对它们进行初始化。如果您有一个直接使用DataSource的bean,请使用@DependsOnDatabaseInitialization注释它的类或@Bean方法,以确保它也在数据库初始化之后被初始化。

1.2 Flyway和Liquibase JDBC URLs

如果你现在定义了spring.flyway.urlspring.liquibase.url,你可能需要提供额外的 usernamepassword 属性。在Spring Boot的早期版本中,这些设置源自 spring.datasource 属性,但这对于提供自己的DataSource bean的人来说是有问题的。

1.3 Spring Data JPA

Spring Data JPA引入了一个新的“getById”方法,它取代了“getOne”。如果你发现你的应用程序正在抛出一个' LazyLoadingException ',请将任何现有的' getById '方法重命名为' getXyzById '(其中' xyz '是一个任意字符串)。要了解更多细节,请阅读更新的Spring Data JPA参考文档.

1.4 Spring Data Solr

在2021.0.0版本中从Spring Data中删除后,Spring Data Solr的自动配置在这个版本中被删除了。

1.5 Secure Info Endpoint

默认情况下,' /info 'actuator endpoint 不再在web上公开。此外,如果引用了Spring Security,而您的应用程序没有自定义安全配置,则默认情况下endpoint 需要经过身份验证的访问。
请参阅关于exposedsecured actuator endpoints的文档,以更改这些新的默认值。

1.6 Task Scheduling Harmonization with Spring Integration

Spring Integration现在重用一个可用的' TaskScheduler ',而不是配置自己的' TaskScheduler '。在依赖于auto-configuration的典型应用程序设置中,这意味着Spring Integration使用池大小为1的auto-configuration任务调度器。要恢复Spring Integration的默认10个线程,请使用spring.task.scheduling.pool.size属性。

1.7 默认Expression Language (EL) 实现

Spring Boot的web和验证启动器中包含的EL实现已经发生了变化。Tomcat的实现(org.apache.tomcat.embed.tomcat-embed-el)取代了替Glassfish的实现(org.glassfish:jakrta.el)。

1.8 Messages in the Default Error View

默认错误视图中的 message 属性现在被删除,而不是当它没有显示时被清空。如果解析错误响应JSON,可能需要处理缺少的项。

1.9 Logging Shutdown Hooks

现在,我们默认为基于jar的应用程序注册一个日志shutdown hook,以确保在JVM退出时释放日志资源。如果应用程序作为war部署,则不会注册shutdown hook,因为Servlet容器通常处理日志记录问题。大多数应用希望使用shutdown hook。但是,如果您的应用程序具有复杂的上下文层次结构,那么您可能需要禁用它,可以使用logging.register-shutdown-hook 属性。

10、Gradle Default jar and war Tasks

Spring Boot Gradle Plugin不再自动禁用标准的Gradle jarwar 任务。相反,我们应用classifier 对这些任务。
如果您希望禁用这些任务,参考文档包括更新的示例

11、Cassandra限流属性

Spring Boot不再为spring.data.cassandra.request.throttler属性提供默认值。如果你依赖max-queue-size, max-concurrent-requests, max-requests-per-seconddrain-interval ,你应该设置对你的应用有意义的值。

12、定制jOOQ的DefaultConfiguration

为了简化jOOQ DefaultConfiguration的定制,现在可以定义实现DefaultConfigurationCustomizer的bean。现在已经不支持,定制器回调应该用于定义一个或多个*Provider bean。

13、Groovy 3

Groovy的默认版本已经升级到3.x。如果您正在使用Groovy并同时使用Spock,那么您还应该升级到最新兼容Groovy 3.0的Spock 2.0版本。或者,使用 groovy.version降级回Groovy 2.5。

14、最低要求的变化

用Gradle构建的项目现在需要Gradle 6.8或更高版本。

15、Hibernate Validator 6.2

Hibernate Validate的默认版本已升级到6.2.x。Hibernate Validator 6.2更改了表达式语言插入约束消息的方式。请参见这篇来自Hibernate Validator团队的博客文章了解更多细节。

16、在Spring Boot 2.3 and 2.4弃用的代码

反映Spring Boot发布兼容策略, Spring Boot 2.3中已弃用的代码已在Spring Boot 2.5中删除。在Spring Boot 2.4中已弃用的代码仍然保留,并计划在Spring Boot 2.6中删除。

2、New and Noteworthy

Check the configuration changelog for a complete overview of the changes in configuration.

Environment Variable Prefixes

It’s now possible to specify a prefix for system environment variables so that you can run multiple different Spring Boot applications in the same environment. Use SpringApplication.setEnvironmentPrefix(…) to set the prefix that you want to use when binding properties.

For example, the following will add a myapp prefix:

SpringApplication application = new SpringApplication(MyApp.class);
application.setEnvironmentPrefix("myapp");
application.run(args);

All properties will now expect a prefixed version. For example, to change the server port you can set MYAPP_SERVER_PORT.

HTTP/2 over TCP (h2c)

All four embedded web containers now support HTTP/2 over TCP (h2c) without any manual customization. To enable h2c, set server.http2.enabled is true and leave server.ssl.enabled set to false (its default value).

As with the existing h2 support, depending on the embedded web server being used, the use of h2c may require additional dependencies. See the reference documentation for details.

Generic DataSource Initialization

A new generic mechanism is now available if you write code that initializes a DataSource. This mechanism is also now used internally to setup correct bean dependencies for Flyway, Liquibase and Script based initialization.

Most developers won’t need to directly make use of the new mechanism. However, if you are developing a third-party starter for a data access library, you may want to provide a DependsOnDataSourceInitializationDetector. See the updated reference documentation for details.

Database Initialization with R2DBC

Support for script-based initialization of an SQL database accessed via R2DBC has been added. By default, scripts on the classpath named schema.sql and data.sql will be applied to the database automatically. The initialization can be customized using the spring.sql.init.* configuration properties. Please see the reference documentation for further details.

Liquibase DataSource

If you define a custom DataSource for use with Liquibase we now configure it using a SimpleDriverDataSource. We previously used a pooling datasource which was unnecessary and inefficient for database initialization.

Layered WARs

The Spring Boot Maven and Gradle plugins now allow you to create layered WARs for use with Docker images. Layered WARs work in a similar way to the Layered JAR support that was provided in earlier versions of Spring Boot. Check out the Gradle and Maven reference documentation for more details.

Docker Image Building Support

Custom Buildpacks

The Maven and Gradle plugins both now support the use of custom Buildpacks. You can set the buildpacks property to point at directories, tar.gz files, specific builder references or Docker images.

See the updated Gradle and Maven reference documentation for more details.

Bindings

The Maven and Gradle plugins now both support volume bindings that can be passed to the buildpack builder. These allow you to bind local paths or volumes for the buildpack to use.

See the updated Gradle and Maven reference documentation for more details.

War Support

Both the Maven and Gradle plugin can now package executable war files into Docker images. The existing mvn spring-boot:image or ./gradlew bootBuildImage commands should be used if you want to create a Docker image for your war.

OpenMetrics for Prometheus

The /actuator/prometheus actuator endpoint can now provide both standard Prometheus as well as OpenMetrics responses. The response returned will depend on the accept header that is provided with the HTTP request.

Metrics for Spring Data Repositories

Actuator will now generate Micrometer metrics for Spring Data repositories. By default, metrics are named spring.data.repository.invocations. To learn more, please see the relevant section of the reference documentation.

@Timed Metrics with WebFlux

Aligning its capabilities with those of Spring MVC, @Timed can now be used to manually enable timing of requests handled by WebFlux controllers and functional handlers. To use manual timing, set management.metrics.web.server.request.autotime.enabled to false.

MongoDB Metrics

When using Actuator, metrics for Mongo’s connection pool and commands sent by the client are now generated automatically. To learn more about MongoDB metrics, please see the relevant section of the reference documentation.

Actuator Endpoint for Quartz

A /quartz endpoint has been added to Actuator. It provides detailed information about Quartz jobs and triggers. Please see the relevant section of the Actuator’s API documentation for further details.

GET requests to actuator/startup

The actuator’s startup endpoint now supports GET requests. Unlike a POST request, a GET request to the endpoint does not drain the event buffer and events will continue to be held in memory.

Abstract Routing DataSource Health

Actuator’s health endpoint now shows the health of the targets of an AbstractRoutingDataSource. Each target DataSource is named using its routing key. As before, to ignore routing data sources in the health endpoint, set management.health.db.ignore-routing-data-sources to true.

Java 16 Support

This release provides support and is tested against Java 16. Spring Boot 2.5 remains compatible with Java 8.

Gradle 7 Support

The Spring Boot Gradle plugin supports and is tested against Gradle 7.0.x.

Jetty 10 Support

Spring Boot 2.5 can now use Jetty 10 as an embedded web server. As Jetty 10 requires Java 11, our default Jetty version will remain as 9.

To upgrade to Jetty 10, use the jetty.version property to override the version. You should also exclude org.eclipse.jetty.websocket:websocket-server and org.eclipse.jetty.websocket:javax-websocket-server-impl from spring-boot-starter-jetty as they are Jetty 9-specific.

Documentation Updates

The HTML documentation published by the project has an updated look-and-feel and some new features. You can now easily copy snippets of code to the clipboard by hovering over the sample and clicking the "copy" icon. In addition, many of the samples now include full import statements that can be shown or hidden as required.

We also now have a "dark theme" switcher at the top of each document.

Miscellaneous

Apart from the changes listed above, there have also been lots of minor tweaks and improvements including:

Dependency Upgrades

Spring Boot 2.5 moves to new versions of several Spring projects:

Numerous third-party dependencies have also been updated, some of the more noteworthy of which are the following:

3、Notable Deprecations in Spring Boot 2.5

The following notable deprecations have been made in Spring Boot 2.5

上一篇下一篇

猜你喜欢

热点阅读