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).
這個就是增加一個配置放在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.
簡單解釋就是在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ū)別。。。