Spring Framework 7 brings new concept for null safety and relies on Java 25
The new Spring Framework uses JSpecify for null safety. It also introduces API versioning and offers a new retry concept for resilience.
(Image: LilKar/Shutterstock.com)
VMWare Tenzu has released Spring Framework 7. The open-source framework for the Java platform brings, among other things, new functions for improved resilience, null safety, API versioning, and Java messaging in the current release.
For the JDK, Spring Framework 7 targets Java 25, and for Enterprise Java, Jakarta EE 11 is the base. For interoperability with Kotlin, it relies on version 2.2 of the programming language, and for unit tests, it works with JUnit 6.0.
Null Safety with JSpecify
To prevent errors from handling null pointers -- the inventor of the null reference, Tony Hoare, apologized in 2009 for the "billion-dollar mistake"-- the current Spring Framework uses JSpecify. This makes the previous annotations according to JSR 305 (Java Specification Request) obsolete (deprecated).
JSpecify provides annotations that help prevent null pointer errors: @Nullable indicates that the value can potentially be null, while types annotated with @NonNull must never be null.
Videos by heise
Further details on the benefits of JSpecify are shown in a post on the Spring blog.
Resilience for Spring Applications
The Spring team has introduced new features for resilience that replace the now-retired Spring Retry project. In Spring Framework 7, the features are included in org.springframework.core.retry, which includes RetryTemplate and RetryPolicy, among others.
The annotation @Retryable specifies, among other things, how often and with what delay the application should attempt to retry a failed call, as shown in the following example from the Spring documentation:
@Retryable(
includes = MessageDeliveryException.class,
maxAttempts = 5,
delay = 100,
jitter = 10,
multiplier = 2,
maxDelay = 1000)
public void sendNotification() {
this.jmsClient.destination("notifications").send(...);
}
Whether the resilience functions are triggered or ignored can be configured via @EnableResilientMethods.
API Versioning, Java Messaging, and More
Spring Framework 7 introduces a new concept for API versioning. Developers configure how the API version is resolved and validated. Clients can specify the API version in requests to the RestClient, WebClient and for HTTP clients. Versioning can also be used in testing with the WebTestClient. A post on the Spring blog provides a detailed explanation of API versioning.
In the current release, Spring also gets the JMSClient, which provides functions for sending and receiving messages via the JMS API (Jakarta Messaging).
Also noteworthy is the new RestTestClient as a variant of the WebTestClient, which extends the RestClient with a testing interface. Additionally, the BeanRegistrar interface offers a new method for registering beans.
Further innovations and some removed or deprecated features can be found in the release notes for Spring 7.
(rme)