infoq上的文章瞄到 spring5 GA发布
看了下new features: spring5-newfeatures
1. 起点上升到jdk8了,整个项目基于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的可靠性,就是根据不同的数据库来适配具体的jdbc的操作类,比如WebSphereNativeJdbcExtractor,C3P0NativeJdbcExtractor等
spring5之后用Connection.unwrap
靠。。。。有人测试说这个sql.unwrap性能不行,不如具体的OracleJdbc4NativeJdbcExtractor快。。。怎么办??
3.去掉mock.staticmock JIRA,不支持 AnnotationDrivenStaticEntityMockingControl
没什么用,之前使用需要提前声明mock的属性类型,不支持anyType,而且好像esoteric,所以干脆kill了
4. web.view.tiles2andorm.hibernate3/hibernate4dropped
现在最小支持tiles3 和hibernate5了
5. Dropped support: Portlet, Velocity, JasperReports, XMLBeans, JDO, Guava
General Core Revision
jdk8上的加强
1. 更好的访问属性,基于jdk8的reflection
2. spring 接口 default实现
3. 使用jdk7的Charset和StandardCharset
Non-Null api的声明
Nullable parameters, returns, fields 使用@Nullable
与idea结合的最好,还有Kotlin
一些api不再忍受null
关于Resource接口的修改
使用了NIO readableChannel 和 stream来改造一些方法
spring自己的common-loggine bridge
就是不用在加spring-jcl 或者其他的log bridge来使用log4j,slf4j等
spring-core使用ASM6.0
ASM就是字节码解析运行等的底层jar,具体我也没看过。。。。不知道区别在哪里,有空可以翻一下
core部分的修改
@Nullable的使用, JIRA
在方法实现时使用了@Nullable注解来标记可为空的属性,然后在方法中检查参数不为空(没加的)
这个设计思想类似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,估计是指实现逻辑用上了函数式编程??(字面理解,等下了source看看)
Consistent detection of transaction, caching, async annotations on interface methods.
In case of CGLIB proxies.
在接口方法持续检测事务,缓存,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的时间(我曾经碰到一个问题,需要自己用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
就是原来统一扔MultipartException,现在分出一个MaxUploadSizeExceededException,应对超出大小的情况
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
原来应该没有自带的
Data binding with immutable objects (Kotlin / Lombok /@ConstructorProperties) JIRA
这里描述的问题,主要是使用Lombok的时候,对于不能set的属性,如果有个同名方法,则报错,提供了一种@ConstructorProperties 注解来解决,同理应用在Kotlin中
Support for the JSON Binding API (as an alternative to Jackson and GSON). JIRA
简单说,就是Servlet4.0支持json-b 一种新的json binding协议,然后3.0支持json-p,然后在spring5里通过JsonbHttpMessageConverter来支持,但是Yasson好像没有很好的实现,所以也用了apache的Johnzon 1.1(同时支持json-p + json-b)
Support for Jackson 2.9. JIRA
目前来说,spring直接升级到jackson,没什么太特别的改动,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
这还是关系到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新的交互基础,异步,不阻塞,而不是传统的事件模式,用一个线程池来每个reques同一个线程的方式 spring-webflux , reactive-streams
好了,明显两个新东西需要学习,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出的),好吧老了。。。。跟不上节奏了
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.
并发测试。。。。这个有用
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.
这个还不知道区别。。。