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.
Spring 6 and Spring boot 3 have been released and should be used in new projects. Consider upgrading old projects as well.
1. Baseline Upgrades
To build and run Spring 5 application, you will need a minimum JDK 8 and Java EE 7. Previous JDK and Java EE versions are not supported anymore. To elaborate, Java EE 7 includes –
- Servlet 3.1
- JMS 2.0
- JPA 2.1
- JAX-RS 2.0
- Bean Validation 1.1
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+
2. JDK 9 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.
3. JDK 8 Features are Baked In
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
4. Support for Reactive Programming
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.
5. 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")));
6. Kotlin Support
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.
7. Removed Features
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 !!