SOFTWARE DEVELOPMENT

Spring Boot 3 and Java 21 – What’s New, What Changed, and Enterprise Use Cases

This article is part of a series on software development prepared by Sebastian Pieróg.



The new features in Spring Boot 3 and Java 21 are sparking excitement among developers. And for good reason—many long-standing challenges, such as limited thread availability or complex configuration, are now a thing of the past. With the release of Spring Boot 3 and Java 21, developers gain access to modern tools that simplify development and improve scalability. This article provides an overview of the most important changes in these technologies.

What’s New in Java 21?

Virtual Threads – A Revolution in Thread Management

As part of Project Loom, Java 21 introduces virtual threads. Traditional threads are resource-heavy, with their creation burdening the operating system, which forced developers to rely on thread pools. Virtual threads solve this problem—they are lightweight, managed by the JVM, and can run in the thousands without noticeable overhead.

What’s crucial is that developers don’t need to change their coding style—Virtual Threads look and behave like regular threads but are far more efficient. This means applications can handle significantly more concurrent requests without requiring complex concurrency mechanisms.

Schemat działania Virtual Threads w Javie 21

Pattern Matching and Record Patterns – Cleaner, More Readable Code

Pattern Matching

Pattern Matching enables both type checking and direct use of objects. Java 21 introduces this functionality to the switch block. Previously, developers had to write verbose if blocks, use instanceof, and manually cast objects. Now this can be done in a single, concise expression.

In large applications that often operate on generic types, Pattern Matching reduces errors and improves readability. The compiler also verifies whether all cases are covered, which enhances safety. Developers no longer need to worry about manual casting or potential ClassCastException.

Przykład zastosowania Pattern Matching w Javie 21

Record Patterns

Records have already become a common way of defining simple data carrier classes in Java. Record Patterns take this further by enabling direct extraction of record fields within conditional statements. Instead of calling accessor methods manually, developers can bind values directly to variables while performing type checks.

This results in shorter, safer, and more expressive code. The feature is especially useful in large systems with numerous DTOs in circulation. Record Patterns integrate seamlessly with Pattern Matching, creating a consistent object-oriented programming model that enhances readability and simplifies maintenance.

Sealed Classes i Scoped Values –  Improved Application Safety

Sealed Classes

Przykład działania Sealed Classes w Javie 21

Sealed Classes give developers finer control over inheritance hierarchies. A class or interface marked with the sealedkeyword can only be extended by explicitly defined types. This ensures no unexpected implementations appear in the system that could disrupt application logic.

This is particularly valuable in large enterprise systems with complex class and interface structures. Sealed Classes work very well with Record Patterns and Pattern Matching, offering developers a powerful tool for safe and maintainable domain modeling.

Scoped Values

Scoped Values provide an alternative to ThreadLocal. They allow values to be shared within the scope of a thread in a controlled and predictable way. Unlike ThreadLocal, Scoped Values have a clearly defined lifecycle—they only exist within the scope of the invocation where they were defined.

This minimizes the risk of memory leaks and hard-to-detect bugs. They are especially useful with Virtual Threads, enabling the transfer of contextual data without boilerplate code. This is critical for server-side applications handling multiple users simultaneously while keeping data properly isolated. Scoped Values are simple to use and enhance both application security and predictability.

String Templates – Convenient String Interpolation

String Templates, currently available in preview, are among the most practical additions in Java 21. Until now, Java lacked a clean way to perform string interpolation. Developers had to rely on String.format or concatenation, often leading to unreadable code.

String Templates allow variables to be embedded directly in text in a clean, concise way. This improves both readability and security. In the future, the feature is expected to support automatic data sanitization for SQL queries, further enhancing application safety.

What’s New in Spring Boot 3?

Support for Java 17+ and GraalVM Native Image

Java 17+ Requirement

Spring Boot 3 requires Java 17 or later. This enables developers to fully benefit from modern language improvements while ensuring tighter integration with the latest JVM mechanisms. The result is better performance, greater stability, and more concise, maintainable code.

GraalVM Native Image Integration

Spring Boot 3 provides full support for GraalVM Native Image compilation. Applications compiled into native binaries start almost instantly and consume significantly less memory.

This makes them an ideal choice for microservices, serverless functions, and cold-start environments. Configuration is straightforward—simply add the spring-boot-starter-graalvm dependency and build with Maven or Gradle. The result is faster, more resource-efficient applications.

Migration to Jakarta EE 9 and New API in Spring Framework 6.1

Transition to Jakarta 9+

Spring Boot 3 fully adopts the Jakarta EE 9 specification, shifting namespaces from javax.* to jakarta.*. This transition marks a complete move away from Java EE toward modern Java standards.

Although migration may require updating imports and dependencies, it ensures full compatibility with the current enterprise ecosystem.

Application Monitoring

Spring Boot 3 enhances observability through advanced support for Micrometer and the Observation API. Developers can now easily measure method execution times (@Timed), count method invocations (@Count), and monitor operation durations (@Observed).

These capabilities provide greater transparency, helping teams quickly identify performance bottlenecks and monitor runtime behavior effectively.

Virtual Threads in Spring Boot – Enabling and Using Them

Spring Boot 3.2 introduces official support for Java 21 Virtual Threads. By setting spring.threads.virtual.enabled=true, Tomcat, Jetty, and Spring mechanisms can leverage lightweight threads.

This allows blocking code to remain synchronous while achieving high scalability at low cost. The result is cleaner code, more responsive infrastructure, and reduced operational costs.

New APIs: RestClient and JdbcClient

Spring Framework 6.1 adds first-class support for the new RestClient and JdbcClient APIs. These modern alternatives to RestTemplate and traditional JDBC introduce a more functional and declarative programming style.

Spring Boot 3.2 configures them automatically, enabling developers to write cleaner, more testable applications. The new APIs promote higher code quality and increased developer productivity.

Application Monitoring and Scale to Zero – Cloud-Native Features

Spring Boot 3.2 introduces initial support for CRaC (Coordinated Restore at Checkpoint). This feature enables applications to save their state and restore it almost instantly.

Combined with GraalVM, it allows near-zero startup times—critical in cloud-native environments where instances are frequently created and destroyed.

Conclusion – Why Migrate Now?

The changes in Java 21 and Spring Boot 3 go beyond pure technology—they unlock new opportunities. Applications benefit from shorter startup times, lower resource usage, and improved scalability, while developers gain access to modern standards, better performance, and cleaner code.

Enhanced monitoring tools ensure that issues are detected and resolved faster, allowing businesses to respond more effectively to market demands. With improved cloud integration and scalability, enterprises can achieve greater agility.

These innovations prove that the Java ecosystem continues to evolve rapidly. If you’ve postponed migration until now, this is the perfect time to move forward.


Author: Sebastian Pieróg, Senior Fullstack Java Developer, ALTEN Polska