What’s New in Spring Boot 4? Explore the Latest Features and Enhancements

Spring Boot 4, built on Spring Framework 7, introduces elegant API versioning, streamlined Bean registration, null‑safety annotations, simplified HTTP proxy creation, upgraded SPEL, GraalVM native support, Jackson 3.x, newer Servlet/WebSocket versions, and numerous other enhancements, offering developers more powerful and convenient tools.

Programmer DD
Programmer DD
Programmer DD
What’s New in Spring Boot 4? Explore the Latest Features and Enhancements

When creating a new Spring Boot project, Spring Boot 4.0.0 options are now available.

Spring Boot 4 is built on the brand‑new Spring Framework 7.0.0, as shown below:

So what are the important changes? Let’s take a look.

1. Elegant version control

The new version introduces elegant support for API versioning, allowing developers to use the @RequestMapping annotation’s version attribute, as shown:

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class VersionedController {

    @RequestMapping(value = "/user", version = "1")
    public String getUserV1() {
        // version 1 implementation
        System.out.println("Version 1");
        return "Version 1";
    }

    @RequestMapping(value = "/user", version = "2")
    public String getUserV2() {
        // version 2 implementation
        System.out.println("Version 2");
        return "Version 2";
    }
}

Program execution result:

2. Convenient Bean injection

The new version introduces a new BeanRegistrar contract, allowing more flexible Bean registration (multiple Beans at once). Example code:

import org.springframework.beans.factory.BeanRegistrar;
import org.springframework.beans.factory.BeanRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

@Configuration
@Import(MyBeansRegistrar.class)
public class MyConfiguration {
}

class MyBeansRegistrar implements BeanRegistrar {
    @Override
    public void register(BeanRegistry registry, Environment env) {
        registry.registerBean("user", User.class);
        if (env.matchesProfiles("dev")) {
            registry.registerBean(Order.class, spec -> spec
                .supplier(context -> new Order("order_001")));
        }
    }
}

class User {
    private String name;
}

class Order {
    public Order(String name) {
        this.name = name;
    }
    private String name;
}

Write unit tests to prove the registered Bean works:

3. Null‑safety improvements

The new version adopts JSpecify annotations to declare API null‑safety, using @Nullable for values that can be null and @NonNull for non‑null values. IntelliJ IDEA can provide warnings or errors, as shown:

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

public class Person {
    private String name;

    public void setName(@NonNull String name) {
        this.name = name;
    }

    @Nullable
    public String getName() {
        return this.name;
    }
}

IDEA also shows warning messages:

Different IDEA versions display differently; the author uses IDEA 2024, which is required for the new features.

4. Easy HTTP proxy creation

The new version provides the @ImportHttpServices annotation, making it easier to create HTTP interface proxies. Example:

@Configuration(proxyBeanMethods = false)
@ImportHttpServices(group = "weather", types = {FreeWeather.class, CommercialWeather.class})
@ImportHttpServices(group = "user", types = {UserServiceInternal.class, UserServiceOfficial.class})
static class HttpServicesConfiguration extends AbstractHttpServiceRegistrar {
    @Bean
    public RestClientHttpServiceGroupConfigurer groupConfigurer() {
        return groups -> groups.filterByName("weather", "user")
            .configureClient((group, builder) -> builder.defaultHeader("User-Agent", "My-Application"));
    }
}

5. Other seven changes

Other upgrade features include:

SPEL expression upgrade: SPEL now supports null‑safe and Elvis operators, e.g. @Value("#{systemProperties['pop3.port'] ?: 25}").

GraalVM native application support: Using Spring AOT, applications can be compiled to native images, significantly reducing startup time.

Jackson 3.x support: Support for Jackson 2.x is dropped in favor of Jackson 3.x.

Servlet and WebSocket version upgrade: Uses Servlet 6.1 and WebSocket 2.2 as the underlying implementation, requiring deployment on the latest servlet containers such as Tomcat 11+ or Jetty 12.1+.

HttpHeaders optimization: New HttpHeaders API usage, e.g. headers.firstValue("X-Custom-Header").orElse(null).

Feature removals: Spring MVC XML configuration namespace deprecated (use Java config), JUnit 4 support in Spring TestContext deprecated, Jackson 2.x support deprecated, Spring JCL removed.

Higher minimum environment requirements: Jakarta EE 11 (Tomcat 11+), Kotlin 2.x, JSONassert 2.0, GraalVM 23.

For more upgrade information, refer to the official release notes:

https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-7.0-Release-Notes

Conclusion

Programming is a lifelong learning profession. Changes in frameworks and tools provide more convenient and user‑friendly methods, which benefit developers. So let’s learn, use, and experiment with them together.

JavaSpring BootGraalVMBean RegistrationSpring Framework 7
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.