Updates in Java Spring Framework 5.0
Spring Framework 5.0 was launched with some new enhancements and features. At the top level, these new features can be categorized as:
- Core framework revision.
- Core container updates
- JDK baseline update
- Functional programming with Kotlin
- Reactive Programming Model
- Testing improvements
- Library support
Core Framework Revision
The core Spring Framework 5.0 has been revamped to be able to use the new features of Java 8. The key revisions are:
- The method parameters of Spring Framework 5.0 can efficiently access the reflection enhancements of Java 8.
- The interfaces of Core Spring have be revised to provide selective declarations, which are build on Java 8 default methods.
- @NotNull and @Nullable will clearly mark nullable return values and arguments.
- Spring Framework 5.0 also comes with a Commons Logging Bridge Module, known as spring-jcl.
- Defensive programming also gets an upgrade with Resource Abstraction, where the isFile indicator is for getFile method.
Core Container Updates
The framework has a new update called candidate component index. It is like an alternative option to classpath scanning process. It is particularly helpful where there are more than 200 classes. Candidate component index shortens the candidate component identification step.
The build task of any application can state its own spring. components file / META-INF. On compilation the Spring components and JPA entries are flagged.
Indicators at optional injection points can now be done with @Nullable annotations, previously it could be done only through JSR 305's Nullable, Checker Framework's Nullable and Android's Nullable.
JDK Baseline Update
The codebase of Spring Framework 5.0 required Java 8 as minimum requirement. This allows the developers to use all the latest Java updates.
Functional programming with Kotlin
Kotlin is an oject oriented programming language, with Spring Framework 5.0 supporting this language, developers can it for bean registration and functional Web endpoints.
In Spring Framework 5.0, using Kotlin code a Web functional API can be written like this :
{
("/movie" and accept(TEXT_HTML)).nest {
GET("/", movieHandler::findAllView)
GET("/{card}", movieHandler::findOneView)
}
("/api/movie" and accept(APPLICATION_JSON)).nest {
GET("/", movieApiHandler::findAll)
GET("/{id}", movieApiHandler::findOne)
}
}
Reactive Programming Model
Spring comes with a reactive stack Web framework. This framework is highly suitable for event-loop style processing as it is non-blocking and fully reactive.
Reactive streams is a kind of API specification, developed by engineers from Pivotal, Netflix, Typesafe, Oracle, Ret Hat, Spray.io and Twitter. In Spring the streaming support is designed on a Project Reactor, which in turn runs the Reactive Streams API specifications.
Testing improvements
It supports JUnit 5 Jupiter for writing tests and extensions in JUnit 5 and also provides a test engine for running Jupiter-based test. In Spring TestContext Framework, it supports parallel tests execution. WebTestClient is also available for reactive programming model.
Library Support
The following upgraded library versions are supported by Spring Framework 5.0:
- Jackson 2.6+
- EhCache 2.10+ / 3.0 GA
- Hibernate 5.0+
- JDBC 4.0+
- XmlUnit 2.x+
- OkHttp 3.x+
- Netty 4.1+
Undoubtedly reactive programming is the highlight of Spring Framework 5.0. Its features have been added to Spring Security, Spring Data and Spring Integration.