Spring Framework 7 / Spring Boot 4 is bringing first-class API versioning support — and I’ve been playing with it this morning ☕️💻
Until now, we all hacked versioning with:
- URLs like /v1/..., /v2/...
- Custom headers
- Media types like application/vnd.foo.v1+json
…but Spring didn’t really know anything about “versions”. It was just strings in your mappings.
With the new support, you can now:
- Configure a central ApiVersionStrategy (e.g. read version from API-Version header)
- Declare versions directly on mappings:
@GetMapping(path = "/account/{id}", version = "1.1")
public Account getAccountV11(@PathVariable String id) { … }
@GetMapping(path = "/account/{id}", version = "1.2")
public Account getAccountV12(@PathVariable String id) { … }
➡️ Same HTTP method
➡️ Same path
➡️ Different handler based on version 🎯
And on the client side, you can just say:
client.get()
.uri("/account/42")
.apiVersion(1.2)
…and let Spring handle how to inject that version (header, path, etc.).
🎥 below a short demo video where:
I hit /account/1 twice with curl
Only changing the API-Version header
And show how Spring routes to two different methods without changing the URL
What’s your current strategy for API versioning? Path, header, media type… or “we pretend versions don’t exist” 😅?
#Java #Spring #SpringBoot #SpringFramework7 #APIVersioning #REST #Microservices
Go further with Java certification:
Java👇
Spring👇
SpringBook👇