What Is New in Spring Framework 5.1
Spring Framework 5.1 delivers a set of refinements and new capabilities focused on core container, web stack, and data access improvements. This release builds on the foundation of 5.0 with a strong emphasis on JDK 11 compatibility and runtime performance.
| Category | Key Updates |
|---|---|
| Core Container | Support for JDK 11, refined annotation detection, programmatic lookup support for @Named. |
| Web Framework | JSON improvements (Jackson 2.9), Scripting (Kotlin 1.3, JRuby 9.2), Servlet 4.0 support in Spring Test. |
| Data Access | Hibernate 5.3 support, declarative TransactionManager resolution, reactive transaction support. |
| Testing | JUnit 5.2 support, parallel test execution, enhanced SpringBootTest context caching. |
| Kotlin Support | Full support for Kotlin 1.3, null-safety for bean injection, coroutines in Spring MVC and WebFlux. |
How does Spring Framework 5.1 improve core container performance?
The core container gets smarter annotation processing and programmatic bean lookup. Annotation detection skips non-annotated classes faster, which matters for startup time in large applications.
You can now use @Named with the standard javax.inject API for programmatic lookups via BeanFactory. This bridges Spring's powerful container with lighter, standard-based lookups when you need them.
JDK 11 Runtime Support
Spring 5.1 is fully compatible with JDK 11, the next long-term support release. In practice, this means you can run your Spring applications on the latest Java runtime without waiting for framework patches.
What web framework updates should developers know about?
The web stack receives updates across JSON serialization, scripting languages, and Servlet API support. Jackson 2.9 is now the baseline, bringing performance improvements and new module support for your REST APIs.
Scripting support moves forward with Kotlin 1.3 and JRuby 9.2. If you use JSR-223 scripts within Spring, your newer language runtimes are now officially supported.
Servlet 4.0 in Tests
Spring's mock objects for testing now support Servlet 4.0. This allows you to unit-test features like HTTP/2 push without a full container, which speeds up development cycles for modern web apps.
Are there important data access and transaction changes?
Yes, Hibernate 5.3 is now supported. This matters because it aligns Spring's ORM support with the latest Hibernate features and fixes.
Transaction management gets two key upgrades. First, you can declaratively resolve which TransactionManager to use via @Transactional. Second, reactive transaction support is more robust for non-blocking data access patterns.
@Transactional(transactionManager = "ordersTxManager")
public void processOrder() {
// This method uses a specific transaction manager
}
What's new for testing Spring applications?
JUnit 5.2 is fully supported, including its extension model and parallel execution. You can run tests in parallel within a single JVM, which cuts down feedback time in large test suites.
SpringBootTest context caching is more efficient. When you have multiple test classes with identical configuration, Spring reuses the application context between them. This leads to significantly faster test runs in a typical Spring Boot project.
How is Kotlin support enhanced in this release?
Kotlin 1.3 is fully supported, including its new coroutines. You can now use suspending functions directly in @Controller and @RestController classes for Spring MVC and WebFlux.
Spring's null-safety annotations now apply to bean injection points. The Kotlin compiler will warn you if you inject a nullable type into a non-nullable Kotlin parameter, catching potential null pointer issues at compile time.
@Repository
class UserRepository {
fun findById(id: Long): User?
}
@Service
class UserService(@Autowired val userRepository: UserRepository) {
// Kotlin knows userRepository.findById() can return null
}
FAQ
Should I upgrade from Spring Framework 5.0 to 5.1?
Yes, if you're on 5.0. The upgrade path is smooth and brings performance improvements, JDK 11 support, and important library updates like Jackson and Hibernate. It's a recommended maintenance release.
Does Spring 5.1 require Java 11?
No. It supports Java 8, 9, 10, and 11. Java 11 is fully supported, but not mandatory. You can run it on Java 8.
What is the significance of programmatic @Named lookup?
It provides a standard JSR-330 way to look up beans programmatically from the BeanFactory. This is useful for integration code or frameworks that need to dynamically fetch beans by name without full @Autowired injection.
How do the testing improvements affect my Spring Boot applications?
The enhanced context caching in SpringBootTest has an immediate impact. If your Boot app has multiple integration tests with the same configuration, they will start much faster as the test framework reuses the application context.
Can I use Kotlin coroutines with Spring MVC?
Yes. Spring Framework 5.1 introduces support for Kotlin coroutines in both Spring MVC (Servlet stack) and WebFlux (Reactive stack). You can mark controller methods with the suspend keyword.