What Is New in Spring Framework 5.0
Spring Framework 5.0 is a major release focused on modern Java development. It establishes a new baseline, cutting away legacy code and embracing the latest runtime and programming paradigms.
| Category | Key Changes |
|---|---|
| New Baseline | Java 8+ and Java EE 7+ baseline; support for JDK 9 runtime; removal of deprecated packages and APIs. |
| Reactive Stack | Introduction of Spring WebFlux, a reactive web framework built on Reactor 3.1, supporting Reactive Streams across the stack. |
| Language Support | First-class Kotlin support, including functional bean registration and null-safety via extension functions. |
| Testing | Full integration with JUnit 5 Jupiter, parallel test execution in the Spring TestContext Framework. |
| Core Container | Improved performance via selective use of JDK 8 features; programmatic bean registration with functional style. |
| Web Improvements | Support for HTTP/2, Jackson 2.9, Protobuf 3.0, XMLBeans, and Tiles 3.0. Servlet 4.0 support for the PushBuilder. |
How does Spring 5.0 change the Java baseline and runtime support?
Spring 5.0 requires Java 8 or later, making Java 8's lambdas and default methods a foundation for the framework's own code. This allows for internal cleanups and performance optimizations that weren't possible before.
It also provides out-of-the-box support for running on JDK 9, handling classpath visibility with the module system. The framework's own modules are aligned with the Java 9 module system, preparing for future modular deployments.
Removed Packages and Libraries
Several legacy packages were removed to reduce the footprint and maintenance burden. This includes Portlet support, Velocity, JasperReports, and several others. The mock.static and webmvc-config.xml namespaces are also gone.
What is Spring WebFlux and when should I use it?
Spring WebFlux is a new, fully non-blocking, reactive web framework built on Project Reactor. It's designed for high-concurrency, low-latency use cases where traditional thread-per-request models become a bottleneck.
You can use it with two programming models: annotated controllers (similar to Spring MVC) or functional routing and handling. It runs on Servlet 3.1+ containers, Netty, or Undertow. In practice, WebFlux shines for applications with many streaming or real-time connections, like chat or market data feeds.
Reactive Across the Stack
The reactive support isn't just for the web layer. New reactive clients like WebClient and reactive repositories for data stores like MongoDB and Cassandra extend the non-blocking paradigm end-to-end.
What does first-class Kotlin support mean for developers?
Spring 5.0 introduces dedicated extensions that make Kotlin development feel native. You can write concise, idiomatic Kotlin code when building Spring applications.
Key features include null-safe bean injection, functional bean registration with GenericApplicationContext, and Kotlin null-safety support throughout the framework API. This matters because it reduces boilerplate and leverages Kotlin's strengths for more robust application code.
val context = GenericApplicationContext {
registerBean<MyBean>()
registerBean { MyOtherBean(ref<MyBean>()) }
}
How is testing improved in Spring Framework 5.0?
The biggest testing advancement is full integration with JUnit 5 Jupiter. This brings powerful new features like nested tests, dynamic tests, and improved extension points directly into Spring testing.
The Spring TestContext Framework now supports parallel test execution. This can significantly reduce the feedback loop for large test suites. You'll need to ensure your tests are properly isolated, but the performance gain is often worth the effort.
New Annotations and Utilities
New annotations like @DisplayName and @EnabledIf provide better control over test execution and reporting. The SpringExtension bridges Spring's testing support with the JUnit 5 programming model.
What core container and performance enhancements were made?
The core IoC container saw refinements for programmatic configuration and startup performance. The functional bean registration API allows for a more declarative style of wiring outside of annotation scanning.
Performance improvements come from reduced reflection overhead, optimized cache usage, and more efficient algorithm choices internally. For most applications, this means faster startup and slightly lower memory consumption, which is critical in microservices and serverless environments.
Selected JDK 8 Usage
The framework now uses Java 8 features like default methods in its own interfaces, reducing the need for adapter classes. This internal cleanup makes the codebase more maintainable and can have positive ripple effects on performance.
FAQ
Is Spring MVC deprecated now that WebFlux exists?
No, Spring MVC remains fully supported and is the recommended choice for most applications. WebFlux is an alternative for specific reactive use cases. Both can coexist in the same application.
Do I have to use Kotlin or Java 8 to upgrade to Spring 5.0?
You must use Java 8 or higher, but you can continue writing Java 8 code without using lambdas. Kotlin is optional but supported if you choose to adopt it.
What happened to the Portlet support?
The Portlet API support (spring-webmvc-portlet) was removed in Spring 5.0 due to its declining usage and maintenance cost. Applications using Portlets need to stay on Spring Framework 4.3.x or migrate to alternative UI architectures.
Can I use JUnit 4 tests with Spring 5.0?
Yes, JUnit 4 is still supported via the vintage engine. However, you are encouraged to migrate to JUnit 5 Jupiter for new tests to access the latest features.
Does Spring 5.0 support HTTP/2 with Servlet containers?
Yes, Spring 5.0 supports HTTP/2 for Servlet 4.0 compatible containers (like Tomcat 9). It also provides support via the PushBuilder interface for server push, a key feature of HTTP/2.