Spring 5 is the first major release, almost four years after Spring Framework 4.0. During this time, most of the enhancements were done in Spring boot project. In this article, we will quickly go through some exciting features coming in Spring 5.0 release.
Table of Contents Baseline upgrades JDK 9 runtime compatibility Usage of JDK 8 features Reactive programming support A functional web framework Kotlin support Dropped features
To build and run Spring 5 application, you will need minimum JDK 8 and Java EE 7. Previous JDK and Java EE versions are not supported anymore. To elaborate, Java EE 7 includes –
Similar to Java baseline, there are changes in baselines of many other frameworks as well. e.g.
- Hibernate 5
- Jackson 2.6
- EhCache 2.10
- JUnit 5
- Tiles 3
Also, note down the minimum supported versions of various servers.
- Tomcat 8.5+
- Jetty 9.4+
- WildFly 10+
- Netty 4.1+
- Undertow 1.4+
JDK 9 runtime compatibility
Spring 5 release has been very well aligned with JDK 9 release dates. The goal is for Spring Framework 5.0 to go GA right after JDK 9’s GA. Spring 5.0 release candidates are already supporting Java 9 on classpath as well as modulepath.
You can expect good JDK 9 support in GA release.
Usage of JDK 8 features
Until Spring 4.3, JDK baseline version was 6. So Spring 4 had to support Java 6, 7 and 8. To maintain the backward compatibility, Spring framework didn’t adapted many new features which Java 8 brought with itself e.g. Lambda programming.
Spring 5 has baseline version 8, so it uses many new features of Java 8 and 9 as well. e.g.
- Java 8 default methods in core Spring interfaces
- Internal code improvements based on Java 8 reflection enhancements
- Use of functional programming in the framework code – lambdas and streams
Reactive programming support
Reactive programming is one of the most important features of Spring Framework 5.0. Reactive programming provides an alternate style of programming focused on building applications that react to events. Spring Framework 5 embraces Reactive Streams (language-neutral attempt to define reactive APIs) and Reactor (java implementation of Reactive Streams provided by the Spring Pivotal team) for its own reactive use as well as in many of its core APIs.
Spring Web Reactive lives in the new
spring-web-reactive module next to the existing (and popular!) Spring Web MVC that lives in the
spring-webmvc module. Please note that in Spring 5, traditional Spring MVC keeps running on any Servlet 3.1 stack, including Java EE 7 servers.
A functional web framework
Building on top of the reactive features, Spring 5 also provides a functional web framework. It provides features to define endpoints using functional programming style. This framework introduces two fundamental components:
HandlerFunction represents a function that handles incoming requests and generates responses.
RouterFunction serves as an alternative to the
@RequestMapping annotation. It’s used for routing incoming requests to handler functions. e.g.
RouterFunction<String> route = route(GET("/hello-world"), request -> Response.ok().body(fromObject("Hello World")));
Kotlin is a statically typed JVM language that enables code that is expressive, short, and readable. Spring framework 5.0 has good support for Kotlin.
Along with the increase in baseline versions for Java, Java EE and a few other frameworks, Spring Framework 5 removed support for a few frameworks. e.g.
Happy Learning !!
All of my websites are hosted on Bluehost. Why? Because they make it incredibly easy to get a new site up and running with their one-click automatic WordPress Blog installation.
You can use your Bluehost account to host multiple domains—no need to pay more for hosting when you’re ready to start another website.