Spring5 出了!

infoq上的文章瞄到?spring5 GA發(fā)布

看了下new features:?spring5-newfeatures

1. 起點上升到j(luò)dk8了,整個項目基于8了,也就是不懂lamba看不懂source了

2. 準備接9了,

3. 基于j2ee 7, servlet3.1,bean validation 1.1, jpa2.1, jms2.0

tomcat 8.5+ jetty 9.4+

4. 兼容j2ee8, servlet4.0, bean validation 2.0, jpa2.2, json binding api 1.0,?


刪除:

1. 去掉了BeanFactoryLocator 為主的機制,?BeanFactoryLocator機制

這個BeanFactoryLocator主要是用于EJB的集成(后來也被用在SDG(Spring data Gemfire)中

Juergen Hoeller: 提到的,廢棄的原因:

Not only its typical use cases date back to ten years ago, its design is equally old and rather over-generalized. Also, the lifecycle of the contained factories isn't well-defined in such a static registry model with weak reference cleanup


2. 去掉? NativeJdbcExtractor , NativejdbcExractor JIRA

NativeJdbcExtractor主要用來jdbc4.0中的pool, drivers的可靠性,就是根據(jù)不同的數(shù)據(jù)庫來適配具體的jdbc的操作類,比如WebSphereNativeJdbcExtractor,C3P0NativeJdbcExtractor等

spring5之后用Connection.unwrap

靠。。。。有人測試說這個sql.unwrap性能不行,不如具體的OracleJdbc4NativeJdbcExtractor快。。。怎么辦??

3.去掉mock.staticmock? JIRA,不支持? AnnotationDrivenStaticEntityMockingControl

沒什么用,之前使用需要提前聲明mock的屬性類型,不支持anyType,而且好像esoteric,所以干脆kill了

4. web.view.tiles2andorm.hibernate3/hibernate4dropped

現(xiàn)在最小支持tiles3 和hibernate5了

5. Dropped support: Portlet, Velocity, JasperReports, XMLBeans, JDO, Guava


General Core Revision

jdk8上的加強

1. 更好的訪問屬性,基于jdk8的reflection

2. spring 接口 default實現(xiàn)

3. 使用jdk7的Charset和StandardCharset

Non-Null api的聲明

Nullable parameters, returns, fields 使用@Nullable

與idea結(jié)合的最好,還有Kotlin

一些api不再忍受null

關(guān)于Resource接口的修改

使用了NIO readableChannel 和 stream來改造一些方法

spring自己的common-loggine bridge

就是不用在加spring-jcl 或者其他的log bridge來使用log4j,slf4j等

spring-core使用ASM6.0

ASM就是字節(jié)碼解析運行等的底層jar,具體我也沒看過。。。。不知道區(qū)別在哪里,有空可以翻一下

core部分的修改

@Nullable的使用,?JIRA

在方法實現(xiàn)時使用了@Nullable注解來標記可為空的屬性,然后在方法中檢查參數(shù)不為空(沒加的)

這個設(shè)計思想類似guice(https://github.com/google/guice/wiki/UseNullable),也符合當下java8中Optional模式和kotlin中的

Functional style onGenericApplicationContext/AnnotationConfigApplicationContext

Supplier-based bean registration API with bean definition customizer callbacks.

這個沒找到JIRA,估計是指實現(xiàn)邏輯用上了函數(shù)式編程??(字面理解,等下了source看看)

Consistent detection of transaction, caching, async annotations on interface methods.

In case of CGLIB proxies.

在接口方法持續(xù)檢測事務(wù),緩存,async的注解??難道以前沒有????靠

XML configuration namespaces streamlined towards unversioned schemas.

對于xml中的xsd聲明,沒有version的始終使用latest的

Support for candidate component index (as alternative to classpath scanning).

JIRA

這個就是增加一個配置放在meta-inf/下,比如一個spring.components 文件用于標記所有的component,從而減少spring啟動時自動scan的時間(我曾經(jīng)碰到一個問題,需要自己用assembly(maven)工具生成的包沒辦法找到bean,最后加上了生成這些配置的文件,好像是一些xsd)

目前支持jpa entities和components,可以減少編譯運行啟動的時間

spring web mvc

Full Servlet 3.1 signature support in Spring-provided Filter implementations.

所有的servlet3.1 , 支持filter

Support for Servlet 4.0 PushBuilder argument in Spring MVC controller methods.

JIRA

簡單解釋就是在controller的方法中支持從ServletContext中得到PushBuilder,支持Servlet4.0,具體

4.0有啥變化?PushBuilder干嘛用的,我目前不知道

MaxUploadSizeExceededException for Servlet 3.0 multipart parsing on common servers.?JIRA

就是原來統(tǒng)一扔MultipartException,現(xiàn)在分出一個MaxUploadSizeExceededException,應(yīng)對超出大小的情況

Unified support for common media types through MediaTypeFactory delegate.??JIRA

在spring-web中使用spring自己的mine.types文件,工廠莫斯,apache上一個https://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?revision=1752884&view=co

原來應(yīng)該沒有自帶的

Data binding with immutable objects (Kotlin / Lombok /@ConstructorProperties)?JIRA

這里描述的問題,主要是使用Lombok的時候,對于不能set的屬性,如果有個同名方法,則報錯,提供了一種@ConstructorProperties 注解來解決,同理應(yīng)用在Kotlin中

Support for the JSON Binding API (as an alternative to Jackson and GSON).??JIRA

簡單說,就是Servlet4.0支持json-b 一種新的json binding協(xié)議,然后3.0支持json-p,然后在spring5里通過JsonbHttpMessageConverter來支持,但是Yasson好像沒有很好的實現(xiàn),所以也用了apache的Johnzon 1.1(同時支持json-p + json-b)

Support for Jackson 2.9.?JIRA

目前來說,spring直接升級到j(luò)ackson,沒什么太特別的改動,jackson2.9

Support for Protobuf 3.??JIRA

都是在ProtobufHttpMessageConverter中的修改

Support for Reactor 3.1FluxandMonoas well as RxJava 1.3 and 2.1 as return values from Spring MVC controller methods targeting use of the new reactiveWebClient(see below) or Spring Data Reactive repositories in Spring MVC controllers.?

不了解flux,不了解reactive。。。。。

New ParsingPathMatcher alternative to AntPathMatcher with more efficient parsing and?extended syntax.?JIRA

這還是關(guān)系到webflux的路徑match的修改,具體等我看了flux再來了解

@ExceptionHandler methods allow RedirectAttributes arguments (and therefore flash attributes).

豐富了ExceptionHandler注解的功能,能夠 使用flash attribute

Support for ResponseStatusException as a programmatic alternative to @ResponseStatus.?JIRA

這個是對于@ResponseStatus的使用,在解析的時候換了功能(source)

Support script engines that do not implement Invocable via direct rendering of the script provided using ScriptEngine#eval(String, Bindings), and also i18n and nested templates in ScriptTemplateView via the new RenderingContext parameter.?JIRA

腳本解析的時候簡化代碼的意思,具體要看source

Spring's FreeMarker macros (spring.ftl) use HTML output formatting now (requiring FreeMarker 2.3.24+).?

freeMarker2.3.24的marco定義在spring.ftl中

Spring WebFlux

肉戲來了

新增的model,我說我怎么沒聽說過

New?spring-webflux?module, an alternative to spring-webmvc built on a?reactive?foundation -- fully asynchronous and non-blocking, intended for use in an event-loop execution model vs traditional large thread pool with thread-per-request execution model.

這么理解,這個是webflux是一個webmvc新的交互基礎(chǔ),異步,不阻塞,而不是傳統(tǒng)的事件模式,用一個線程池來每個reques同一個線程的方式?spring-webflux?,?reactive-streams

好了,明顯兩個新東西需要學(xué)習,reactive-stream, spring-webflux

Reactive infrastructure in spring-core such as Encoder and Decoder for encoding and decoding streams of Objects;DataBuffer? abstraction, e.g. for using JavaByteBuffer or Netty ByteBuf;ReactiveAdapterRegistry for transparent support of reactive libraries in controller method signatures.

Reactive infrastructure in spring-web including HttpMessageReader and HttpMessageWriter that build on and delegate to Encoder and Decoder; serverHttpHandler with adapters to (non-blocking) runtimes such as Servlet 3.1+ containers, Netty, and Undertow;WebFilter,WebHandler and other non-blocking contract alternatives to Servlet API equivalents.

@Controllerstyle, annotation-based, programming model, similar to Spring MVC, but supported in WebFlux, running on a reactive stack, e.g. capable of supporting reactive types as controller method arguments, never blocking on I/O, respecting back pressure all the way to the HTTP socket, and running on extra, non-Servlet containers such as Netty and Undertow.

New?functional programming model("WebFlux.fn") as an alternative to the@Controller, annotation-based, programming model -- minimal and transparent with an endpoint routing API, running on the same reactive stack and WebFlux infrastructure.

NewWebClient with a functional and reactive API for HTTP calls, comparable to the RestTemplate but through a fluent API and also excelling in non-blocking and streaming scenarios based on WebFlux infrastructure; in 5.0 the AsyncRestTemplate is deprecated in favor of theWebClient.

用到的一些類,看了source再來分析

Kotlin Support

Null-safe API when using Kotlin 1.1.50+

Support for Kotlin immutable classes with optional parameters and default values

Functional bean definition Kotlin DSL.

Functional routing Kotlin DSL for WebFlux.

Leveraging Kotlin reified type parameters to avoid specifying explicitly theClassto use for serialization/deserialization in various APIs likeRestTemplateor WebFlux APIs.

Kotlin null-safety support for@Autowired/@Injectand@RequestParam/@RequestHeader/etc annotations in order to determine if a parameter/bean is required or not.

Kotlin script support inScriptTemplateViewfor both Spring MVC and Spring WebFlux.

Array-like setters added toModel,ModelMapandEnvironement.

Support for Kotlin autowired constructor with optional parameters

Kotlin reflection is used to determine interface method parameters

一堆Kotlin的支持,不懂Kotlin(只知道google出的),好吧老了。。。。跟不上節(jié)奏了

Testing Improvements

測試新增,這個還是有需要了解

Complete support forJUnit 5'sJupiterprogramming and extension models in the Spring TestContext Framework.

SpringExtension: an implementation of multiple extension APIs from JUnit Jupiter that provides full support for the existing feature set of the Spring TestContext Framework. This support is enabled via@ExtendWith(SpringExtension.class).

@SpringJUnitConfig: a composed annotation that combines@ExtendWith(SpringExtension.class)from JUnit Jupiter with@ContextConfigurationfrom the Spring TestContext Framework.

@SpringJUnitWebConfig: a composed annotation that combines@ExtendWith(SpringExtension.class)from JUnit Jupiter with@ContextConfigurationand@WebAppConfigurationfrom the Spring TestContext Framework.

@EnabledIf: signals that the annotated test class or test method is?enabled?if the supplied SpEL expression or property placeholder evaluates to true.

@DisabledIf: signals that the annotated test class or test method is?disabled?if the supplied SpEL expression or property placeholder evaluates to true.

junit5的支持。。。。。還在用4.。。

Support for?parallel test execution?in the Spring TestContext Framework.

并發(fā)測試。。。。這個有用

New?before?and?after?test execution callbacks in the Spring TestContext Framework with support for TestNG, JUnit 5, and JUnit 4 via theSpringRunner(but not via JUnit 4 rules).

New beforeTestExecution() and afterTestExecution() callbacks in theTestExecutionListener API and TestContextManager.

新的before和after

MockHttpServletRequest now has getContentAsByteArray() and getContentAsString() methods for accessing the content (i.e., request body).

新的mock方法

The print() and log() methods in Spring MVC Test now print the request body if the character encoding has been set in the mock request.

mvc test的時候log和print方法

The redirectedUrl() and forwardedUrl() methods in Spring MVC Test now support URI templates with variable expansion.

還是mvc test的時候redictedUrl有新的模版處理,沒用過。。。

XMLUnit support upgraded to 2.3.

這個還不知道區(qū)別。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,702評論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,143評論 3 415
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,553評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,620評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,416評論 6 405
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 54,940評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,024評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,170評論 0 287
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,709評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 40,597評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,784評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,291評論 5 357
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,029評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,407評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,663評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,403評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,746評論 2 370

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