Spring Boot 4 migration notes
Spring Boot 4.0 has been out since November 2025, and sooner or later every Boot 3 application will have to move. These notes follow the official release notes and migration guide: what changed, what breaks, and the order in which I would do it.
The authors' opinion may differ from the editorial position
☰ Contents · 9
The headline changes
From the 4.0 announcement and release notes:
- Spring Framework 7 underneath, on Jakarta EE 11 (Servlet 6.1).
- Java 17 baseline, with support for current JDKs including 25 LTS.
- JSpecify nullability annotations across the Spring portfolio.
- Modular codebase: Boot's own auto-configuration is split into smaller, focused modules and starters.
- API versioning built into Spring MVC and WebFlux.
- HTTP Service Clients: declarative interfaces with group-based configuration.
None of these is optional in the sense of "you can stay on the old way forever", so it is worth understanding each one before you start.
Step 0: get to the latest 3.5.x first
Do not jump from an old 3.x straight to 4.0. Upgrade to the latest 3.5.x, fix every deprecation warning, and only then switch. Deprecated APIs in 3.x are what gets removed in 4.0, and the compiler will tell you about them while you can still build.
Modular starters
The monolithic auto-configure jar is split into modules per technology. For most applications that means checking which starters you depend on, because some were renamed or split. The migration guide provides "classic" starters that pull in the broad set of modules, which is a reasonable first step:
<!-- temporary: brings back the wide classpath while you migrate -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-classic</artifactId>
</dependency>
Once the application starts and tests pass, replace it with the specific starters you actually use. The benefit is a smaller classpath and fewer auto-configurations evaluated on startup.
Null safety with JSpecify
Spring's APIs are now annotated with JSpecify. In Java this mostly matters if you run a nullness checker such as NullAway; in Kotlin it changes the types the compiler sees, so code that compiled before may need ? or !! decisions.
For your own code:
// package-info.java
@NullMarked
package com.example.billing;
import org.jspecify.annotations.NullMarked;
public @Nullable Invoice findOpen(String accountId) { ... }
Within a @NullMarked package everything is non-null unless marked @Nullable. Start with one package, not the whole codebase.
API versioning
Versioning is now a first-class attribute of request mappings. Configure how the version is resolved once:
@Configuration
class WebConfig implements WebMvcConfigurer {
@Override
public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("API-Version");
}
}
Then map versions on the endpoints:
@RestController
@RequestMapping("/accounts")
class AccountController {
@GetMapping(path = "/{id}", version = "1.0")
AccountV1 getV1(@PathVariable String id) { ... }
@GetMapping(path = "/{id}", version = "2.0")
AccountV2 getV2(@PathVariable String id) { ... }
}
If you already version with path prefixes (/v1/...), you do not have to move. The new mechanism helps most when you need several versions of a few endpoints, not of the whole API.
HTTP Service Clients
Declarative clients (@HttpExchange) existed since Framework 6, but needed manual factory wiring. Now they are registered in groups:
@HttpExchange("/repos")
interface RepoClient {
@GetExchange("/{owner}/{name}")
Repo get(@PathVariable String owner, @PathVariable String name);
}
@Configuration
@ImportHttpServices(group = "github", types = RepoClient.class)
class ClientsConfig {}
The base URL, timeouts and other settings are configured per group in the application properties; the exact keys are in the reference documentation. This replaces a fair amount of hand-written RestClient setup.
Testing changes
@MockBeanand@SpyBean, deprecated in 3.4, are gone. Use@MockitoBeanand@MockitoSpyBean.- Jackson 3 is the default JSON library; tests that compare serialized JSON byte for byte are the ones most likely to need attention.
@WebMvcTest(AccountController.class)
class AccountControllerTest {
@MockitoBean AccountService service;
}
Checklist
- Upgrade to the latest 3.5.x, clear all deprecations.
- Check your JDK: 17 minimum, ideally 21 or 25.
- Switch to 4.0 with the classic starters; get the build green.
- Replace
@MockBean/@SpyBean. - Review Jackson-dependent code and JSON tests.
- Check third-party libraries for Jakarta EE 11 and Boot 4 support.
- Replace classic starters with specific ones.
- Adopt JSpecify, API versioning and HTTP Service Clients where they help, as separate changes.
- Keep Spring Security on the latest patch: four CVEs were published on 20 August 2026.
Sources
- Spring Boot 4.0, 20.11.2025 — release announcement: Framework 7, JSpecify, Java 17, API versioning, HTTP Service Clients
- Spring Boot 4.0 Release Notes — full list of changes
- Spring Boot 4.0 Migration Guide — modular starters, classic starters, removed APIs
- JSpecify —
@NullMarked,@Nullable - OpenJDK: JDK 25 — LTS, 16.09.2025
- Spring Security advisories — CVE-2026-41707, 47841, 47877, 47842, 20.08.2026
Comments 7
Quick one: if we're starting a new service on Boot 4 today, is there any reason to pick Java 17 over 25? Our infra team kind of defaults to 17 everywhere.
>>1
For a new service I would not pick 17. It is only the minimum Boot 4 accepts. 25 is the current LTS, and it brings things you get for free, like Compact Object Headers (opt-in in 25) and the virtual thread improvements. The usual reason to stay on 17 is a shared base image or an agent that has not been certified on newer JDKs, so that is the question to ask your infra team.
5 more in other languages
jackson 3 это вообще больно? у нас кастомные сериализаторы на каждом углу, переписывать все или есть совместимость
>>3
Больно ровно настолько, насколько у вас кода вокруг Jackson. Пакет сменился (
com.fasterxml.jackson.databind→tools.jackson.databind), часть API переименована, поэтому кастомные сериализаторы придётся как минимум перекомпилировать с новыми импортами. В migration guide описано, как временно остаться на Jackson 2; это разумно как промежуточный шаг, чтобы не совмещать переход на Boot 4 с переписыванием сериализации.Уточнение к пункту 9: на сводной странице spring.io/security у этих четырёх CVE нет описаний, поэтому по ней нельзя понять, затронуты ли именно вы. Практичный вывод тот же, что в статье: обновиться до последнего патча своей ветки Spring Security и следить за страницами конкретных CVE, когда там появятся детали.
В статье не нашёл про встроенные серверы. У нас Undertow, с ним что-то меняется?
>>6
Да, по migration guide поддержку Undertow в Boot 4 убрали: он пока не совместим с Servlet 6.1. Остаются Tomcat и Jetty. Если вы держались за Undertow из-за потребления памяти, сравните с Tomcat на своём нагрузочном тесте; с виртуальными потоками (
spring.threads.virtual.enabled=true) картина может отличаться от той, что была при выборе.Sign in to comment