Spring Boot 2.3 版本升級說明

Spring Boot 2.3 版本升級說明

這是官方的Spring Boot 2.3 版本升級說明,本文將對其作出個人理解厢拭。對于配置屬性變更或者不常用組件的變更畦贸,過于繁瑣趋厉,我就跳過了。

Changes to minimum requirements

Spring Boot now requires:

  • 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)

Gradle和Jetty的依賴最低要求版本提升了乡数。

Validation Starter no longer included in web starters

As of #19550, Web and WebFlux starters do not depend on the validation starter by default anymore. If your application is using validation features, for example you find that javax.validation.* imports are not being resolved, you’ll need to add the starter yourself.
For Maven builds, you can do that with the following:

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

spring-boot-starter-web 不再包含依賴 spring-boot-starter-validation,需要手動引入。如果你有使用@Valid、@NotNull 等 javax.validation 下的校驗注解,則會對你產(chǎn)生一點影響。有些項目也會引入hibernate-validator (groupId:org.hibernate.validator)依賴代替酬姆,基本沒有差別浮定。

Unique DataSource Name By Default

By default, a unique name is generated on startup for the auto-configured DataSource. This impacts the use of the H2 console as the database URL no longer refers to testdb.
You can disable this behavior by setting spring.datasource.generate-unique-name to false.

    public String determineDatabaseName() {
        if (this.generateUniqueName) {
            if (this.uniqueName == null) {
                this.uniqueName = UUID.randomUUID().toString();
            }
            return this.uniqueName;
        }
        if (StringUtils.hasLength(this.name)) {
            return this.name;
        }
        if (this.embeddedDatabaseConnection != EmbeddedDatabaseConnection.NONE) {
            return "testdb";
        }
        return null;
    }

2.2和2.3版本里確定使用名稱的方法沒有修改方灾,只是屬性被給予了默認值true痛单,只有手動設(shè)置為false即可快压。

Jackson

This release upgrades to Jackson 2.11 which includes a change to the default formatting of java.util.Date and java.util.Calendar. Please see FasterXML/jackson-databind#2643 for details.

時間 1970-01-01T01:00:00.123+0100 中的+0100 是指時區(qū)影響下的時間偏移量蔫劣,0000是UTC,0100則是東一區(qū)个从,加一小時脉幢。java8和joda time都是 +01:00格式,而jackson還保留老格式嗦锐。在2.11版本中與java8統(tǒng)一格式了嫌松。看這里的時間實現(xiàn)代碼

Spring Cloud Connectors starter has been removed

The Spring Cloud Connectors starter was deprecated in 2.2 in favor of Java CFEnv. This starter has been removed, and Spring Cloud Connectors dependencies are no longer included in Spring Boot’s managed dependencies.

依賴 spring-boot-starter-cloud-connectors 已經(jīng)廢棄了,這是跟國外云平臺部署有關(guān)的項目奕污,國內(nèi)用到的應(yīng)該很少萎羔。

Embedded Servlet web server threading configuration

The configuration properties for configuring the threads used by embedded Servlet web servers (Jetty, Tomcat, and Undertow) have moved to dedicated threads groups. The properties can now be found in server.jetty.threads, server.tomcat.threads, and server.undertow.threads. The old properties remain in a deprecated form to ease migration.

配置屬性變更,現(xiàn)在線程配置有 server.tomcat.threads.minSpare 和server.tomcat.threads.max碳默。

ApplicationContextRunner disables bean overriding by default

For consistency with SpringApplication, ApplicationContextRunner now disables bean overriding by default. If you need to use bean overriding for a test, withAllowBeanDefinitionOverriding can be used to enable it.

ApplicationContextRunner是一個測試輔助類贾陷,參考文章[分享一個 Spring Boot 提供的測試輔助類 ApplicationContextRunner]
(https://blog.csdn.net/weixin_42189048/article/details/124847651)。

WebServerInitializedEvent and ContextRefreshedEvent

As part of introducing support for graceful shutdown, web server initialisation is now performed at the end of application context refresh processed rather than immediately after refresh processing has completed. As a result, the WebServerInitializedEvent is now published before the ContextRefreshedEvent.

事件的啟動順序為WebServerInitializedEvent在ContextRefreshedEvent之前嘱根,參考文章Spring 常用的一些事件髓废。

Java 14 support

Spring Boot 2.3 adds support for Java 14. Java 8 and 11 are also supported.

Spring Boot 2.3 現(xiàn)在支持java8、java11该抒、java14慌洪。

Graceful shutdown

Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and Servlet-based web applications. When enabled using server.shutdown=graceful, upon shutdown, the web server will no longer permit new requests and will wait for a grace period for active requests to complete. The grace period can be configured using spring.lifecycle.timeout-per-shutdown-phase. Please see the reference documentation for further details.

配置屬性 server.shutdown 可以開啟優(yōu)雅關(guān)機,等待請求完成后凑保,再終止應(yīng)用冈爹,spring.lifecycle.timeout-per-shutdown-phase 可以設(shè)置等待,就像鎖等待時間一樣欧引,如果超時則強行關(guān)閉應(yīng)用犯助。

Spring Data Neumann
R2DBC support

When r2dbc is on the classpath, a ConnectionFactory is auto-configured with a similar arrangement than a jdbc DataSource. If Spring Data is on the classpath, repositories are auto-configured as well, as usual.
R2DBC support also adds an health indicator for the connection factory, metrics for ConnectionPool and a test slice, @DataR2dbcTest.

R2DBC 是一個通過反應(yīng)式編程操作、連接數(shù)據(jù)庫的驅(qū)動程序维咸。2022起步不久。參考文章Spring Data R2DBC快速上手指南

Date-Time conversion in web applications

The conversion of time and date-time values in web applications is now configurable via application properties. This complements that existing support for formatting date values. For MVC, the properties are spring.mvc.format.time and spring.mvc.format.date-time respectively. For WebFlux, the properties are spring.webflux.format.time and spring.webflux.format.date-time respectively.
In addition to taking a typical formatting pattern, the properties for configuring the formatting of dates, times, and date-times now support a value of iso. When set, the corresponding ISO-8601 formatting will be applied.
The iso values is supported by the following properties:

  • 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

在spring boot項目里試了下癌蓖,并不生效瞬哼,只有加上jackson的配置才有效。不明白是什么原因租副。

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
RSocket support for Spring Integration

Spring Boot now provides auto-configuration for Spring Integration’s RSocket support.
If spring-integration-rsocket is available, developers can configure an RSocket server using "spring.rsocket.server.*" properties and let it use IntegrationRSocketEndpoint or RSocketOutboundGateway components to handle incoming RSocket messages.

RSocket協(xié)議采用二進制點對點的數(shù)據(jù)傳輸坐慰,主要用于分布式架構(gòu)中,是一種基于Reactive Streams規(guī)范標準實現(xiàn)的新的網(wǎng)絡(luò)通信第七層(應(yīng)用層)協(xié)議用僧。參考文章SpringBoot使用RSocket協(xié)議结胀。

Binding to Period

If a property needs to express a period of time, you can do so using a java.time.Period property. Similar to the Duration support, an easy format is supported (i.e. 10w for 10 weeks) as well as metadata support.

StringToPeriodConverter是新添加的類型轉(zhuǎn)換服務(wù)類,作為字符串到Period類的轉(zhuǎn)換器被添加到 ApplicationConversionService 類里责循,ApplicationConversionService 類在應(yīng)用啟動的時候會被實例化糟港,作為配置屬性以及應(yīng)用上下文屬性解析的工具。

推薦文章

Spring Boot 2.3.0正式發(fā)布:優(yōu)雅停機院仿、配置文件位置通配符新特性一覽 (qq.com)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末秸抚,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子歹垫,更是在濱河造成了極大的恐慌剥汤,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件排惨,死亡現(xiàn)場離奇詭異吭敢,居然都是意外死亡,警方通過查閱死者的電腦和手機暮芭,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門鹿驼,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人谴麦,你說我怎么就攤上這事蠢沿。” “怎么了匾效?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵舷蟀,是天一觀的道長。 經(jīng)常有香客問我面哼,道長野宜,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任魔策,我火速辦了婚禮匈子,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘闯袒。我一直安慰自己虎敦,他們只是感情好游岳,可當我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著其徙,像睡著了一般胚迫。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上唾那,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天访锻,我揣著相機與錄音,去河邊找鬼闹获。 笑死期犬,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的避诽。 我是一名探鬼主播龟虎,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼茎用!你這毒婦竟也來了遣总?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤轨功,失蹤者是張志新(化名)和其女友劉穎旭斥,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體古涧,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡垂券,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了羡滑。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片菇爪。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖柒昏,靈堂內(nèi)的尸體忽然破棺而出凳宙,到底是詐尸還是另有隱情,我是刑警寧澤职祷,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布氏涩,位于F島的核電站,受9級特大地震影響有梆,放射性物質(zhì)發(fā)生泄漏是尖。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一泥耀、第九天 我趴在偏房一處隱蔽的房頂上張望饺汹。 院中可真熱鬧,春花似錦痰催、人聲如沸兜辞。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽弦疮。三九已至夹攒,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間胁塞,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工压语, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留啸罢,地道東北人。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓胎食,卻偏偏與公主長得像扰才,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子厕怜,可洞房花燭夜當晚...
    茶點故事閱讀 44,724評論 2 354

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