
Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:
Once the early-adopter seats are all used, the price will go up and stay at $33/year.
Last updated: March 27, 2025
With only a short while until the release of Spring Boot 3, now seems like a good time to check out what’s new.
While there was already support for Java 17 before, this LTS version now gets the baseline.
When migrating from LTS version 11, Java developers will benefit from new language features. Since Java itself isn’t the topic of this article, we’ll only name the most important new features for Spring Boot developers. We can find additional details in the separate articles for Java 17, 16, 15, 14, 13, and 12.
Java records (JEP 395, see Java 14 Record Keyword) were intended to be used as a quick way to create data carrier classes, i.e. the classes whose objective is to simply contain data and carry it between modules, also known as POJOs (Plain Old Java Objects) and DTOs (Data Transfer Objects).
We can easily create immutable DTOs:
public record Person (String name, String address) {}
Currently, we need to be careful when combining them with Bean Validation because validation constraints aren’t supported on constructor arguments, such as when the instance is created on JSON deserialization (Jackson) and put into a controller’s method as a parameter.
With JEP 378, it’s now possible to create multi-line text blocks without the need to concatenate strings on line breaks:
String textBlock = """
Hello, this is a
multi-line
text block.
""";
Java 12 introduced switch expressions (JEP 361), which (like all expressions) evaluate a single value, and can be used in statements. Instead of combining nested if–else-operators (?:), we can now use a switch–case-construct:
DayOfWeek day = DayOfWeek.FRIDAY;
int numOfLetters = switch (day) {
case MONDAY, FRIDAY, SUNDAY -> 6;
case TUESDAY -> 7;
case THURSDAY, SATURDAY -> 8;
case WEDNESDAY -> 9;
};
Pattern Matchings were elaborated in Project Amber and found their way to the Java Language. In the Java Language, they can help to simplify the code for instanceof evaluations.
We can use them directly with instanceof:
if (obj instanceof String s) {
System.out.println(s.toLowerCase());
}
We can also use it within a switch–case statement:
static double getDoubleUsingSwitch(Object o) {
return switch (o) {
case Integer i -> i.doubleValue();
case Float f -> f.doubleValue();
case String s -> Double.parseDouble(s);
default -> 0d;
};
}
Sealed classes can limit inheritance by specifying allowed subclasses:
public abstract sealed class Pet permits Dog, Cat {}
We can find more details in Sealed Classes and Interfaces in Java.
The most important change might be the jump from Java EE to Jakarta EE9, where the package namespace changed from javax.* to jakarta.*. As a result, we need to adjust all imports in our code whenever we use classes from Java EE directly.
For example, when we access the HttpServletRequest object within our Spring MVC Controller, we need to replace:
import javax.servlet.http.HttpServletRequest;
with:
import jakarta.servlet.http.HttpServletRequest;
Of course, we don’t have to use the types of the Servlet API very often, but this is unavoidable if we use bean validation and JPA.
We should also be aware of this when we use external libraries that depend on Java/Jakarta EE (e.g. we have to use Hibernate Validator 7+, Tomcat 10+, and Jetty 11+).
Spring Framework 6 and Spring Boot 3 need the following minimum versions:
Two overarching topics have received particular attention: Native Executables and Observability. Overarching means that:
Building native executables and deploying them to GraalVM gets a higher priority. So the Spring Native initiative is moving into Spring proper.
For AOT generation, there’s no need to include separate plugins, we can just use a new goal of the spring-boot-maven-plugin:
mvn spring-boot:aot-generate
Native Hints will also be part of the Spring core. Testing infrastructure for this will be available with Milestone 5 (v6.0.0-M5).
Spring 6 introduces Spring Observability – a new initiative that builds on Micrometer and Micrometer Tracing (formerly Spring Cloud Sleuth). The goal is to efficiently record application metrics with Micrometer and implement tracing through providers, such as OpenZipkin or OpenTelemetry.
There’s auto-configuration for all of these in Spring Boot 3, and the Spring projects are working on instrumenting themselves using the new Observation API.
We can find more details about it in the dedicated article.
One of the most important new features is the support for RFC7807 (Problem Details Standard). Now we won’t need to include separate libraries, like Zalando Problem.
Another smaller change is that HttpMethod is no longer an enum, but a class that allows us to create instances for extended HTTP methods, e.g. those defined by WebDAV :
HttpMethod lock = HttpMethod.valueOf("LOCK");
At least some outdated servlet-based integrations are dropped, like Commons FileUpload (we should use StandardServletMultipartResolver for multipart file uploads), Tiles, and FreeMarker JSP support (we should use FreeMarker template views instead).
There are a few hints for project migration that we should know. The recommended steps are:
As we’ve learned, migrating to Spring Boot 3 and Spring 6 will be a migration to Java 17 and Jakarta EE 9 too. If we attach great importance to observability and native executables, we’ll benefit the most from the upcoming major release.