Spring Boot 2.5 Release Notes

本文主要參考官文文檔。主要目的方便版本升級使用遍愿,對于需要升級部分進行翻譯存淫,對于新增特性等后續(xù)部分未做處理

1、 Upgrading from Spring Boot 2.4

1.1 SQL Script DataSource Initialization

在Spring Boot 2.5版本中沼填,支持"schema.sql" 和"data.sql"的方法被重新設(shè)計了桅咆。DataSource 初始化,“spring.datasource." 屬性已經(jīng)棄用坞笙,取而代之的是新的"spring.sql.init岩饼。"屬性荚虚。 這些屬性還可以用于初始化通過R2DBC訪問的SQL數(shù)據(jù)庫。

schema.sqldata.sql 文件

在Spring Boot 2.5.1及以上版本中籍茧,新的SQL初始化屬性支持檢測JDBC和R2DBC的嵌入式數(shù)據(jù)源版述。默認情況下,SQL數(shù)據(jù)庫初始化只在使用嵌入式內(nèi)存數(shù)據(jù)庫時執(zhí)行寞冯。如果是非嵌入式數(shù)據(jù)庫渴析,要初始化一個SQL數(shù)據(jù)庫,請設(shè)置“spring.sql.init.mode=always”吮龄;要禁用初始化俭茧,請設(shè)置“spring.sql.init.mode=never”。

單獨憑證

新的基于的腳本的SQL數(shù)據(jù)庫初始化不支持使用單獨的憑據(jù)對結(jié)構(gòu)(DDL)和數(shù)據(jù)(DML)更改螟蝙。這降低了復雜性恢恼,并使其功能與Flyway和Liquibase保持一致。如果您需要為結(jié)構(gòu)和數(shù)據(jù)初始化單獨的憑證胰默,請定義自己的bean(org.springframework.jdbc.datasource.init.DataSourceInitializer)场斑。

Hibernate 和 data.sql

默認情況下,data.sql腳本在初始化Hibernate之前運行。這使基于腳本的基本初始化行為與Flyway和Liquibase的行為保持一致牵署。如果你想使用data.sql作為schema被Hibernate創(chuàng)建漏隐,設(shè)置 spring.jpa.defer-datasource-initialization=true。雖然不建議混合使用數(shù)據(jù)庫初始化技術(shù)奴迅,但這也允許也您使用schema.sql腳本在' data.sql '之前執(zhí)行青责,在hibernate創(chuàng)建的schema之上構(gòu)建。

初始化順序

某些眾所周知類型的bean(如JdbcOperations)將被排序取具,以便在數(shù)據(jù)庫初始化之后對它們進行初始化脖隶。如果您有一個直接使用DataSource的bean,請使用@DependsOnDatabaseInitialization注釋它的類或@Bean方法暇检,以確保它也在數(shù)據(jù)庫初始化之后被初始化产阱。

1.2 Flyway和Liquibase JDBC URLs

如果你現(xiàn)在定義了spring.flyway.urlspring.liquibase.url,你可能需要提供額外的 usernamepassword 屬性块仆。在Spring Boot的早期版本中构蹬,這些設(shè)置源自 spring.datasource 屬性,但這對于提供自己的DataSource bean的人來說是有問題的悔据。

1.3 Spring Data JPA

Spring Data JPA引入了一個新的“getById”方法庄敛,它取代了“getOne”。如果你發(fā)現(xiàn)你的應用程序正在拋出一個' LazyLoadingException '科汗,請將任何現(xiàn)有的' getById '方法重命名為' getXyzById '(其中' xyz '是一個任意字符串)藻烤。要了解更多細節(jié),請閱讀更新的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 需要經(jīng)過身份驗證的訪問峭跳。
請參閱關(guān)于exposedsecured actuator endpoints的文檔,以更改這些新的默認值缺前。

1.6 Task Scheduling Harmonization with Spring Integration

Spring Integration現(xiàn)在重用一個可用的' TaskScheduler '蛀醉,而不是配置自己的' TaskScheduler '。在依賴于auto-configuration的典型應用程序設(shè)置中衅码,這意味著Spring Integration使用池大小為1的auto-configuration任務調(diào)度器拯刁。要恢復Spring Integration的默認10個線程,請使用spring.task.scheduling.pool.size屬性逝段。

1.7 默認Expression Language (EL) 實現(xiàn)

Spring Boot的web和驗證啟動器中包含的EL實現(xiàn)已經(jīng)發(fā)生了變化垛玻。Tomcat的實現(xiàn)(org.apache.tomcat.embed.tomcat-embed-el)取代了替Glassfish的實現(xiàn)(org.glassfish:jakrta.el)。

1.8 Messages in the Default Error View

默認錯誤視圖中的 message 屬性現(xiàn)在被刪除奶躯,而不是當它沒有顯示時被清空帚桩。如果解析錯誤響應JSON,可能需要處理缺少的項嘹黔。

1.9 Logging Shutdown Hooks

現(xiàn)在账嚎,我們默認為基于jar的應用程序注冊一個日志shutdown hook,以確保在JVM退出時釋放日志資源儡蔓。如果應用程序作為war部署郭蕉,則不會注冊shutdown hook,因為Servlet容器通常處理日志記錄問題喂江。大多數(shù)應用希望使用shutdown hook召锈。但是,如果您的應用程序具有復雜的上下文層次結(jié)構(gòu)开呐,那么您可能需要禁用它烟勋,可以使用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 赴邻,你應該設(shè)置對你的應用有意義的值。

12啡捶、定制jOOQ的DefaultConfiguration

為了簡化jOOQ DefaultConfiguration的定制姥敛,現(xiàn)在可以定義實現(xiàn)DefaultConfigurationCustomizer的bean。現(xiàn)在已經(jīng)不支持瞎暑,定制器回調(diào)應該用于定義一個或多個*Provider bean彤敛。

13、Groovy 3

Groovy的默認版本已經(jīng)升級到3.x了赌。如果您正在使用Groovy并同時使用Spock墨榄,那么您還應該升級到最新兼容Groovy 3.0的Spock 2.0版本∥鹚或者袄秩,使用 groovy.version降級回Groovy 2.5。

14逢并、最低要求的變化

用Gradle構(gòu)建的項目現(xiàn)在需要Gradle 6.8或更高版本之剧。

15、Hibernate Validator 6.2

Hibernate Validate的默認版本已升級到6.2.x筒狠。Hibernate Validator 6.2更改了表達式語言插入約束消息的方式猪狈。請參見這篇來自Hibernate Validator團隊的博客文章了解更多細節(jié)。

16辩恼、在Spring Boot 2.3 and 2.4棄用的代碼

反映Spring Boot發(fā)布兼容策略雇庙, 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:

  • management.endpoints.web.cors.allowed-origin-patterns can now be used to configure the allowed origin patterns for Actuator endpoints (#24608)

  • HttpSessionIdListener beans are now automatically registered with the servlet context (#24879)

  • Couchbase now uses the auto-configured ObjectMapper by default (#24616)

  • Elasticsearch’s Sniffer is now auto-configured when its elasticsearch-rest-client-sniffer module is on the classpath (#24174)

  • spring.data.cassandra.controlconnection.timeout can now be used to configure the timeout of Cassandra’s control connection (#24189)

  • spring.kafka.listener.only-log-record-metadata can now be used to configure what’s logged when retries are being attempted (#24582)

  • Support for Apache Phoenix, auto-detecting jdbc:phoenix JDBC URLs (#24114)

  • Configuration properties for Rabbit’s key store and trust store algorithms (#24076)

  • The /actuator discovery page can now be disabled using the management.endpoints.web.discovery.enabled property.

  • The /actuator/configprops and actuator/env endpoints now have additional-keys-to-sanitize properties that can be used to sanitize keys.

  • You can now use a EndpointObjectNameFactory if you want to customize the name of JMX actuator endpoints.

  • A new DataSourceBuilder.derivedFrom(…) method has been added that allows you to build a new DataSource that’s derived from an existing one.

  • When Spring Security is on the classpath, configuration properties can now be bound to RSAPublicKey and RSAPrivateKey.

  • The RabbitMQ ConnectionFactory used by Spring AMQP can now be customized using a ConnectionFactoryCustomizer bean.

  • Embedded database auto-configured can now be controlled using the new spring.datasource.embedded-database-connection configuration property. It can be set to any of the values of EmbeddedDatabaseConnection, including none to disable embedded database auto-configured entirely.

  • CloudPlatform can now automatically detect Azure App Service.

  • server.tomcat.keep-alive-timeout can be used to configure how long Tomcat will wait for another request before closing a keep-alive connection.

  • server.tomcat.max-keep-alive-requests can be used to control the maximum number of requests that can be made on a keep-alive connection before it is closed.

  • spring.webflux.session.cookie.same-site can be used to configure WebFlux’s SameSite cookie policy. It is lax by default.

  • Apache HttpClient 5 is now auto-configured for use with WebClient.

  • A new ApplicationEnvironment class has been introduced which should improve a small performance boost.

  • You can now configure Netty memory using the spring.netty.leak-detection property.

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:

  • Kotlin 1.5

  • Groovy 3.0

  • Flyway 7.7

  • Liquibase 4.3

  • Jackson 2.12

  • Kafka 2.7

  • Cassandra Driver 4.10

  • Embedded Mongo 3.0

  • Hibernate Validator 6.2

  • Jersey 2.33

  • Mockito 3.7

  • MongoDB 4.2

  • JUnit Jupiter 5.7

  • Elasticsearch 7.12

3聘萨、Notable Deprecations in Spring Boot 2.5

The following notable deprecations have been made in Spring Boot 2.5

  • ActuatorMediaType and ApiVersion in org.springframework.boot.actuate.endpoint.http in favor of equivalents in org.springframework.boot.actuate.endpoint

  • Support for beans that implement jOOQ’s *Provider callback interfaces or Settings has been deprecated. A DefaultConfigurationCustomizer should be used instead.

  • EntityManagerFactoryDependsOnPostProcessor in org.springframework.boot.autoconfigure.data.jpa has been relocated to org.springframework.boot.autoconfigure.orm.jpa

  • spring.artemis.host and spring.artemis.port are deprecated. Please use spring.artemis.broker-url instead.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末竹椒,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子米辐,更是在濱河造成了極大的恐慌胸完,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,723評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡佳遂,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,485評論 2 382
  • 文/潘曉璐 我一進店門锨能,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事址遇∠ㄗ瑁” “怎么了?”我有些...
    開封第一講書人閱讀 152,998評論 0 344
  • 文/不壞的土叔 我叫張陵倔约,是天一觀的道長秃殉。 經(jīng)常有香客問我,道長跺株,這世上最難降的妖魔是什么复濒? 我笑而不...
    開封第一講書人閱讀 55,323評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮乒省,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘畦木。我一直安慰自己袖扛,他們只是感情好,可當我...
    茶點故事閱讀 64,355評論 5 374
  • 文/花漫 我一把揭開白布十籍。 她就那樣靜靜地躺著蛆封,像睡著了一般。 火紅的嫁衣襯著肌膚如雪勾栗。 梳的紋絲不亂的頭發(fā)上惨篱,一...
    開封第一講書人閱讀 49,079評論 1 285
  • 那天,我揣著相機與錄音围俘,去河邊找鬼砸讳。 笑死,一個胖子當著我的面吹牛界牡,可吹牛的內(nèi)容都是我干的簿寂。 我是一名探鬼主播,決...
    沈念sama閱讀 38,389評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼宿亡,長吁一口氣:“原來是場噩夢啊……” “哼常遂!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起挽荠,我...
    開封第一講書人閱讀 37,019評論 0 259
  • 序言:老撾萬榮一對情侶失蹤克胳,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后圈匆,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體漠另,經(jīng)...
    沈念sama閱讀 43,519評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,971評論 2 325
  • 正文 我和宋清朗相戀三年臭脓,在試婚紗的時候發(fā)現(xiàn)自己被綠了酗钞。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,100評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖砚作,靈堂內(nèi)的尸體忽然破棺而出窘奏,到底是詐尸還是另有隱情,我是刑警寧澤葫录,帶...
    沈念sama閱讀 33,738評論 4 324
  • 正文 年R本政府宣布着裹,位于F島的核電站,受9級特大地震影響米同,放射性物質(zhì)發(fā)生泄漏骇扇。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,293評論 3 307
  • 文/蒙蒙 一面粮、第九天 我趴在偏房一處隱蔽的房頂上張望少孝。 院中可真熱鬧,春花似錦熬苍、人聲如沸稍走。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,289評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽婿脸。三九已至,卻和暖如春柄驻,著一層夾襖步出監(jiān)牢的瞬間狐树,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,517評論 1 262
  • 我被黑心中介騙來泰國打工鸿脓, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留抑钟,地道東北人。 一個月前我還...
    沈念sama閱讀 45,547評論 2 354
  • 正文 我出身青樓答憔,卻偏偏與公主長得像味赃,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子虐拓,可洞房花燭夜當晚...
    茶點故事閱讀 42,834評論 2 345

推薦閱讀更多精彩內(nèi)容