Spring Boot 3 brings significant changes that every Java developer should understand. After successfully migrating several enterprise applications, I want to share the key insights and lessons learned.
Why Upgrade?
Spring Boot 3 requires Java 17 as the minimum version, but I recommend going straight to Java 21 for its LTS status and powerful features like virtual threads, pattern matching, and record patterns.
Key Changes in Spring Boot 3
1. Jakarta EE 9+ Migration
The most significant change is the shift from javax. to jakarta. namespace. This affects:- Servlet API (javax.servlet → jakarta.servlet)
- JPA annotations (javax.persistence → jakarta.persistence)
- Validation annotations (javax.validation → jakarta.validation)
// Before (Spring Boot 2.x)
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
// After (Spring Boot 3.x)
import jakarta.persistence.Entity;
import jakarta.validation.constraints.NotNull;
2. Native Image Support
Spring Boot 3 has first-class support for GraalVM native images:@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Build native image:
./mvnw -Pnative native:compile
3. Observability with Micrometer
The new observability features make distributed tracing seamless:@RestController
public class OrderController {
private final ObservationRegistry registry;
@GetMapping("/orders/{id}")
public Order getOrder(@PathVariable Long id) {
return Observation.createNotStarted("order.fetch", registry)
.observe(() -> orderService.findById(id));
}
}
Migration Steps
- Update Java Version: Ensure Java 17+ (preferably 21)
- Update Dependencies: Modify pom.xml or build.gradle
- Fix Namespace Changes: javax. to jakarta.
- Review Security Config: WebSecurityConfigurerAdapter is removed
- Test Thoroughly: Especially integration tests
Performance Improvements
In our production environment, we observed:
- 30% faster startup time
- 25% reduction in memory footprint
- Improved throughput with virtual threads
Conclusion
While the migration requires effort, Spring Boot 3 with Java 21 provides significant benefits in performance, security, and developer experience. Start planning your migration today!