Spring / Spring Boot 4 Basics Interview Questions
What is Jakarta EE 11 and what changes does it bring in Spring Boot 4?
Spring Boot 4 moves the Jakarta EE baseline from version 9/10 (used in Boot 3.x) to Jakarta EE 11. This brings updated specifications for persistence, validation, servlets, and WebSockets.
| Specification | Version | Key changes |
|---|---|---|
| Jakarta Servlet | 6.1 | Required by Spring Boot 4; Undertow incompatible (removed) |
| Jakarta Persistence (JPA) | 3.2 | Detached entities no longer silently reassociated; stricter persistence context rules |
| Jakarta Bean Validation | 3.1 | Improved constraint validation and messaging |
| Jakarta WebSocket | 2.2 | Updated WebSocket API |
| Hibernate ORM | 7.1 | Managed version; stricter detached entity behaviour |
// All javax.* imports from Spring Boot 2.x are gone in Boot 4 // They must be jakarta.* (this was also true in Boot 3 but Boot 4 enforces it) // WRONG (will not compile in Boot 4): import javax.persistence.Entity; import javax.validation.constraints.NotNull; import javax.servlet.http.HttpServletRequest; // CORRECT: import jakarta.persistence.Entity; import jakarta.validation.constraints.NotNull; import jakarta.servlet.http.HttpServletRequest; // The OpenRewrite recipe handles automated migration: // Migrate_To_Jakarta_EE_10 recipe covers remaining javax.* -> jakarta.* // Hibernate 7.1 breaking change: detached entities // Boot 3: silently reassociated (lenient) // Boot 4: throws exception if you try to persist a detached entity without explicit merge @Transactional public void updateOrder(Order detachedOrder) { // Boot 3: orderRepo.save(detachedOrder) might silently merge // Boot 4: be explicit: orderRepo.save(entityManager.merge(detachedOrder)); }
Critical breaking change: Undertow has been removed entirely from Spring Boot 4 because it is not yet compatible with Servlet 6.1. Any application using Undertow as its embedded container must migrate to Tomcat 11 or Jetty 12.1 before upgrading to Spring Boot 4.
More Related questions...