史上最全 SpringBoot 2.1.0.RELEASE 版本特性介紹(全文英譯版)

Spring Boot 2.1.RELEASE?

參考鏈接:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#new-and-noteworthy

Spring Boot 2.1 Release Notes

Upgrading from Spring Boot 2.0

Deprecations from Spring Boot 2.0

在Spring Boot 2.0中棄用的類、方法和屬性已經在這個版本中刪除了。請確保在升級之前沒有調用已棄用的方法。

Spring Framework 5.1

Spring Boot 2.1 使用 Spring Framework 5.1. 請參考它的升級指南-upgrade guide,了解任何可能影響您的應用程序的更改。

Bean Overriding

默認情況下禁用了Bean重寫,以防止Bean被意外地重寫。如果依賴于重寫,則需要設置spring.main.allow-bean-definition-overriding=true.

Auto-Configuration Exclusion

排除現在被一致地應用,而不僅僅是局部地應用。這適用于在@EnableAutoConfiguration,?@SpringBootApplication,?@ImportAutoConfiguration或?spring.autoconfigure.exclude屬性。

Actuator 'info' and 'health' Endpoint Security

如果spring-security在沒有任何安全配置的類路徑上,那么/info和/health現在將公開以保持一致性。如果在類路徑上有spring-security,但不提供任何安全配置,則需要顯式保護它們。

Servlet Path

The?server.servlet.path?property has moved to?spring.mvc.servlet.path. If you were relying on that property programmatically to know the path of the?DispatcherServlet?please use?DispatcherServletPath?instead.

server.servlet.path?屬性已移至spring.mvc.servlet.path。如果您通過編程的方式依賴該屬性來了解DispatcherServlet的路徑,請使用DispatcherServletPath。

@WebMvcTest and @WebFluxTest Security Configuration

用戶配置現在自動包含在web片測試中。@WebMvcTest查找WebSecurityConfigurer bean,而@WebFluxTest查找ServerHttpSecurity bean。

Logging Refinements

Spring Framework 5.1在使用web應用程序(Spring MVC或Spring WebFlux)時重新訪問了調試日志輸出。如果你試圖調試一個應用程序,并且你想恢復Spring Boot 2.0風格的日志記錄,你應該在application.properties中添加以下內容:

logging.level.web=debug

您可能還想設置spring.http.log-request-details為true,記錄實際請求的詳細信息。默認情況下,此屬性為false,因為它可能暴露敏感信息。

Narayana JTA Support

為了支持與Narayana版本更加一致的官方支持,Narayana的支持已經被刪除。如果你使用的是spring-boot-starter-jta-narayana,新的坐標如下:

? ? me.snowdrop? ? narayana-spring-boot-starter? ? 2.0.1

請參考?the documentation?以了解更多細節。

ActiveMQ Pooling

If you were using?activemq-pool, support has been removed in this release in favor of?pooled-jms?that offers the same features while being JMS 2.0 compliant. You can update your build as follows:

如果您正在使用activemq-pool,那么在這個版本中已經刪除了對pooled-jms的支持,pooled-jms提供了相同的特性,同時兼容JMS 2.0。你可以更新你的構建如下:

HttpPutFormContentFilter

HttpPutFormContentFilter?has been deprecated in favor of?FormContentFilter. As a result the?spring.mvc.formcontent.putfilter.enabled?property is no longer defined. If you were using this feature, please update to?spring.mvc.formcontent.filter.enabled.

HttpPutFormContentFilter已經被棄用,取而代之的是FormContentFilter。?spring.mvc.formcontent.putfilter.enabled 結果屬性不在被定義。如果你正在使用這個特性,請更新到spring.mvc.formcontent.filter.enabled。

OAuth2 Client Configuration

The structure of the?spring.security.oauth2.client.registration?has been reworked in a single tree rather than having an?authorizationcode?and?clientcredentials?sub namespace.

spring.security.oauth2.client.registration?的結構已經在在單個樹中重新注冊,而不是使用authorizationcode和clientcredentials子名稱空間。

Micrometer 'all' SLA Handling

management.metrics.distribution.sla錯誤地描述了一個all meter ID可以用于為所有度量設置SLA?。這個特性不能正確地實現,因為單位可能會根據儀表類型不同而不同。

InfluxDB HttpClient Customization

在前面,聲明OkHttpClient.Builder bean足以定制InfluxDB使用的客戶端。要確保隔離此類自定義,請定義一個InfluxDbOkHttpClientBuilderProvider?bean。

Maven Plugin

finalName屬性不再是可定制的,以與標準Maven插件的行為保持一致。

如果您正在定制repackage目標,那么主執行現在有一個必須指定的repackage id,參考the updated sample.。

Spring Version POM Property

在spring-boot-dependencies POM中定義的spring.version屬性已被重命名。要覆蓋Spring Framework版本,現在應該使用?spring-framework.version屬性。除非絕對必要,我們通常建議您堅持使用托管框架版本。

Removal of 'spring.provides' Files

starter?可以聲明META-INF/spring.provides,以便IDE能夠找出它所提供的依賴項。掃描starter POM以尋找它聲明的直接依賴項應該足以作為一種指示。如果您是第三方啟動器的負責人,并且聲明了這個文件,那么可以刪除它。

Thymeleaf Spring Security Extras

Thymeleaf的Spring Security Extras模塊的依賴管理和自動配置已經從?thymeleaf-extras-springsecurity4 切換到?thymeleaf-extras-springsecurity5。如果您正在使用模塊,則應該更新您的pom.xml或build.gradle依賴thymleaf -extras-springsecurity5。

Json Simple

不再提供json-simple的依賴項管理,使用它的JsonParser實現也已刪除。

Jersey 1

Jersey 1 不再支持。請升級到 Jersey 2.

Hibernate EhCache Support

如果你使用hibernate-ehcache來使用EhCache 2作為Hibernate的二級緩存提供商,它在Hibernate 5.3中已經棄用。

Endpoint ID names

如果您已經開發了自己的執行器@Endpoint bean,那么您應該確保它們遵循Spring Boot 2.1中引入的更嚴格的命名規則。具體來說,IDs應該是只包含字母數字的,并且必須以字母開頭(有關完整細節,請參閱EndpointId類文檔)。

如果你用 -?or?.?字符 Spring Boot 2.1將記錄一個警告并要求您遷移到正確的格式。

Lombok

Spring Boot 2.1已經升級到Lombok?從1.16.x 到 1.18.x。在1.18中,默認情況下Lombok將不再生成私有的、無參數的構造函數。在?lombok.config?configuration file?中,可以通過設置 lombok.noArgsConstructor.extraPrivate=true 啟動它。有關Lombok更改的更多信息,請參閱其更改日志-changelog

Java Persistence API dependency

作為升級到Hibernate 5.3的一部分,托管Java持久化API依賴關系已經從org.hibernate.javax.persistence:hibernate-jpa-2.1-api更改為?javax.persistence:javax.persistence-api。如果您正在使用spring-boot-starter-data-jpa或通過Hibernate傳遞依賴于API,那么您將不受此更改的影響。

JpaProperties

特定于hibernate的屬性已經從JpaProperties移到一個名為HibernateProperties的單獨類中。如果你正在使用JpaProperties. getHibernateProperties(HibernateSettings),你現在應該同時注入HibernateProperties和JpaProperties來確定屬性:

Consistent max HTTP header size across all embedded web servers

The default max HTTP header size is now consistent across the four supported embedded web servers (Jetty, Netty, Tomcat, and Undertow) and is 8KB. The size can be customized using the?server.max-http-header-size?property.

默認的最大HTTP報頭大小現在在四個支持的嵌入式web服務器(Jetty、Netty、Tomcat和Undertow)中是一致的,是8KB??梢允褂胹erver.max-http-header-size屬性。

New and Noteworthy

Tip Check?the configuration changelog?查看配置更改的完整概述。

Third-party Library Upgrades

Spring Boot 2.1構建于Spring Framework 5.1之上,并且需要Spring Framework 5.1。

我們已經盡可能地升級到其他第三方jar的最新穩定版本。這個版本中一些值得注意的依賴升級包括:

Tomcat 9

Undertow 2

Hibernate 5.3

JUnit 5.2

Micrometer 1.1

Java 11 Support

Spring Boot 2.1仍然與Java 8兼容,但現在也支持Java 11。我們配置了持續集成,以針對最新的Java 11版本構建和測試Spring Boot。

DataSize Support

如果一個屬性需要以字節或類似的方便單位表示大小,它可以公開org.springframework.util.unit.DataSize屬性。與我們在Spring Boot 2.0中引入的持續時間支持類似,數據大小支持一種簡單的格式(即10MB?for 10 兆字節)和元數據支持。所有相關配置屬性都已更新,以使用新類型。

Context ApplicationConversionService Support

ApplicationConversionService?現在默認注冊到SpringApplication創建的環境和BeanFactory中。這允許你直接使用應用程序轉換器和Spring Framework?的核心項目,比如@Value注釋:

Profile Expression

Profile matching has been improved to support?an expression format. For instance?production & (us-east | eu-central)?indicates a match if the?production?profile is active?and?either the?us-eas to reu-central?profiles are active.

配置文件匹配已得到改進,以支持一種表達式格式-?an expression format。例如,production & (us-east | eu-central) 表示匹配,如果production 配置文件是激活的,并且 us-east 和??eu-central 配置文件是激活的。

配置文件表達式可以使用如下:

Enable componets using?@Profile

Load?multi-profile YAML Documents

Enable Logback configuration using?<springProfile>

Task Execution

Spring Boot現在為ThreadPoolTaskExecutor提供自動配置。如果你正在使用@EnableAsync,你的自定義TaskExecutor可以被刪除,以便從spring.task.execution?namespace中進行定制。使用TaskExecutorBuilder可以輕松創建自定義ThreadPoolTaskExecutor。

Task Scheduling

與新的任務執行支持類似,當指定@EnableScheduling時,Spring Boot自動配置ThreadPoolTaskScheduler。任務調度程序可以使用spring.task.scheduling?進行定制。默認情況下,TaskSchedulerBuilder也是可用的。

Logging Groups

Logger groups can be defined to allow related loggers to be configured in one go. For example, you could declare a?tomcat?group that allows you to configure?org.apache.catalina,?org.apache.coyote?and?org.apache.tomcat?loggers with a single key:

可以定義記錄器組,以允許一次性配置相關的記錄器。例如,您可以聲明一個允許配置具有單獨key的org.apache.catalina,?org.apache.coyote和org.apache.tomcat?日志記錄器的tomcat組。

方便的web和sql組是開箱即用的。See the?reference guide?for details.

Maven Plugin

指定參數已經改進為系統屬性(system properties)和環境變量(environment variables)的專用選項。也可以重新打包并替換分類工件,查看分類器屬性的更新文檔-the updated documentation。

Bootstrap mode for JPA setup

Spring Data Lovelace introduces a 'bootstrap mode' for the repositories. Spring Boot exposes a property that can be set to control the boostrap mode of JPA repositories. For instance, to defer initialization of JPA repositories, simply add the following to your configuration:

Spring Data Lovelace為存儲庫引入了一種“bootstrap mode”。Spring Boot公開了一個屬性,可以設置該屬性來控制JPA存儲庫的引導模式。例如,要延遲JPA存儲庫的初始化,只需在配置中添加以下內容:

spring.data.jpa.repositories.bootstrap-mode=deferred

當將模式設置為延遲時,JPA設置將在一個單獨的線程中進行。

Kafka Streams Support

自動配置現在提供給Kafa Streams當一個org.apache.kafka:kafka-streams?依賴關系被聲明了。詳情請參閱更新的the updated Spring Boot documentation?文檔和Spring Kafka documentation?文檔。

Spring Data JDBC Support

Spring Data包括對JDBC的存儲庫支持,并將自動為CrudRepository上的方法生成SQL。當必要的依賴項在類路徑上時,Spring Boot將自動配置Spring Data的JDBC存儲庫。它們可以通過spring-boot-starter-data-jdbc的單個依賴項添加到項目中。

關于Spring Data JDBC的完整細節,請參閱reference documentation.

JMS ConnectionFactory Caching

The auto-configured?ConnectionFactory?is cached by default using?CachingConnectionFactory?until the pooling option is enabled or?spring.jms.cache.enabled?is set to?false. Pooling option has also been extended to Artemis (see?spring.jms.artemis.pool.*).

自動配置的ConnectionFactory默認使用CachingConnectionFactory進行緩存,直到啟用 pooling?選項或spring.jms.cache.enabled?設置為false。pooling?選項也被擴展到Artemis(參見spring.jms.artemis.pool.*)。

Elasticsearch REST Clients

作為Jest的替代選項,RestClient和RestHighLevelClient的自動配置提供了spring.elasticsearch.rest.*名稱空間中的可配置選項。

JUnit 5

All?@…? annotations are meta-annotated with?@ExtendWith(SpringExtension.class)?so this redundant part of the setup can be removed if you’re using JUnit 5. Spring Boot also uses a?maven-surefire-plugin?version that does not require any custom setup to use JUnit 5.

所有的@…Test注解都是用?@ExtendWith(SpringExtension.class)進行元注解的,所以如果您使用JUnit 5,就可以刪除這個多余的設置部分。Spring Boot還使用maven-surefire-plugin版本,使用JUnit 5不需要任何自定義設置。

Security

OAuth2 WebFlux Support

Support for WebFlux OAuth2 login has been added. OpenID Connect providers are easier to configure using an?issuer-uri?which is the URI that the it asserts as its Issuer Identifier.

添加支持WebFlux OAuth2登錄。使用?issuer-uri (其聲明為發布者標識符的URI)更容易配置OpenID連接提供者。

OAuth2 resource server support

If you have?spring-security-oauth2-resource-server?on your classpath, Spring Boot can set up an OAuth2 Resource Server as long as a JWK Set URI is specified. For instance:

如果您的類路徑上有spring-security-oauth2-resource-server,那么只要指定了JWK集URI, Spring Boot就可以設置OAuth2資源服務器。例如:

MVC和WebFlux應用程序都支持這一點。

Non-web OAuth Applications

現在,編寫非web OAuth應用程序變得更容易了,因為我們提供了一個自動配置的InMemoryReactiveClientRegistrationRepository bean,而不管應用程序類型是什么。如果您正在編寫一個不使用嵌入式web服務器的應用程序(例如CLI應用程序),您現在可以直接注入并使用配置的注冊存儲庫。

Actuator Endpoints

Caches Endpoint

A new?/actuator/caches?endpoint lists the available?CacheManager?instances and their respective caches with basic metadata. Seethe APIfor more details.

一個新的/actuator/caches端點列出了可用的CacheManager實例和它們各自的帶有基本元數據的緩存。查看the API了解更多細節。

Spring Integration Graph Endpoint

If you are using Spring Integration, a graph representation of all Spring Integration components can be exposed at?/actuator/integrationgraph. Please seethe APIfor more details.

如果您正在使用Spring Integration,所有Spring Integration?組件的圖形表示可以在/actuator/integrationgraph處公開。詳情請參閱the API。

Health Endpoint

現在可以使用HealthIndicatorRegistry bean在運行時添加和刪除HealthIndicator。運行狀況端點也得到了改進,可以在必要時查詢特定的指示器。例如?/actuator/health/db只執行 “db” HealthIndicator。詳情請參閱the API

Apache Cassandra的反應性HealthIndicator?可用。

Micrometer

Common Micrometer Tags

通用標簽可以聲明地應用到所有儀表,如下面的例子所示:

上面的例子為所有值分別為us-east-1和prod的儀表添加了region和stack標簽。

Auto-configuration Support For New Metrics

指標覆蓋率得到了改進,包括:

Hibernate metrics

Spring Framework’s?WebClient

Kafka consumer metrics

Log4j2 metrics

Jetty server thread pool metrics

Server-side Jersey HTTP request metrics

Auto-configuration support for new registries

以下指標注冊表現在在類路徑上自動配置:

AppOptics

Humio

KariosDB

此外,還添加了對Prometheus push gateway的支持。

Additional histogram configuration properties

新的management.metrics.distribution.maximum-expected-value.*和management.metrics.distribution.minimum-expected-value.*?屬性可用于控制每米(per-meter basis)的最大值和最小期望值。

Miscellaneous

除了上面列出的變化,還有很多小的調整和改進,包括:

Jackson 可見性(visibility)使用spring.jackson.visiblity.*進行配置。

使用自動配置的WebServiceTemplateBuilder更容易創建WebServiceTemplate。

當使用Devtools時,錯誤頁面顯示堆棧跟蹤。

不再需要導出虛擬資源(ResourceConfig?)來啟用Jersey支持。

JNDI查找已經得到改進,默認情況下啟用了resourceRef。

可以通過RabbitRetryTemplateCustomizer定制Rabbit基礎設施使用的RetryTemplate。

默認RabbitTemplate的接收隊列現在是可配置的

Tomcat的最大swallow大小現在可以通過屬性進行配置

HTTP/2 with Reactor Netty Server 現在被支持。

Kafka自動配置現在支持errorHandler、transactionManager和afterRollbackProcessor bean。

添加了對全局生成唯一?JMX ObjectNames的支持(而不是將此特性限制在執行器端點(?Actuator Endpoints))

配置屬性元數據現在是有序的,棄用的項出現在最后。

關于Health.Builder?的withDetails方法現在也支持Map。

A reactive?ReactiveJwtDecoder?is now auto-configured when you have an issuer url defined.

當您定義了一個?issuer url時,一個響應式ReactiveJwtDecoder現在是自動配置的。

BackgroundPreinitializer可以被禁用,如果一個spring.backgroundpreinitializer.ignore 系統屬性被設置。

HiddenHttpMethodFilter?可以被啟動通過使用屬性。

The JAP starter POM 現在開箱即用在 Java 9+

MongoDB的自動配置現在將退出當?com.mongodb.client.MongoClient? bean被定義(以及更常見的com.mongodb.MongoClient)。

您現在可以選擇使用Jetty RS作為web客戶端的HTTP驅動程序

在spring.quartz空間添加了幾個配置選項。

@ConditionalOnEnabledEndpoint可以使用在任何component (例如:僅端點需要的內容,如果端點被禁用,則不應該創建這些內容).

@ConditionalOnMissingServletFilter?是值得獲得尊重在 FilterRegistration?beans當測試是否缺少一個Filter?bean時。

@WebMvcTest也會自動配置Spring Data REST(例如支持排序和可分頁請求參數)。

切片測試(slice tests)現在都有一個properties屬性,可以在必要時一致地自定義環境。

支持添加了多個RestDocsMockMvcConfigurationCustomizer

安全配置現在應用到WebTestClient。有關測試安全端點的更多信息,請參閱Spring Security參考文檔的相關部分-relevant section

@WebFluxTest現在支持WebExceptionHandlers?

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)現在可以為管理服務器生成一個單獨的隨機端口。

自動配置排除現在被一致地應用。

Deprecations in Spring Boot 2.1

setConnectTimeout(int)和setReadTimeout(int)已被棄用,取而代之的是需要持續時間(Duration)的類似方法。

使用int設置數據大小的方法已被棄用,并被采用DataSize的變量所取代。

management.endpoints.jmx.unique-names已被棄用,取而代之的是spring.jmx.unique-names。

@AutoConfigureMockMvc?上的安全屬性已被棄用,取而代之的是Spring Security’s?@WithMockUser 注解。

RestTemplateBuilder.basicAuthorization已被棄用,取而代之的是basicAuthentication。

REQUEST_WRAPPER_FILTER_MAX_ORDER?in?AbstractFilterRegistrationBean?and?FilterRegistrationBean 已經被 OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER代替。

Configuration Property Changes

spring.security.oauth2.client.registration.login.*.redirect-uri-template?屬性已被棄用,取而代之的是spring.security.oauth2.client.registration.login.*.redirect-uri。

spring.security.oauth2.resource.jwt.jwk.set-uri?屬性已經改名為 spring.security.oauth2.resourceserver.jwt.jwk-set-uri。

spring.cloud.enabled 屬性已經被刪除(如果需要禁用云連接器,請排除CloudServiceConnectorsAutoConfiguration)。

所有 management.metrics.binders.*.enabled?屬性被刪除,取而代之的是 直接排除自動配置。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,517評論 6 539
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,087評論 3 423
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 177,521評論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,493評論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,207評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,603評論 1 325
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,624評論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,813評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,364評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,110評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,305評論 1 371
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,874評論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,532評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,953評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,209評論 1 291
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,033評論 3 396
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,268評論 2 375

推薦閱讀更多精彩內容