Quick revision
The short answer
Four of the five imports change in a Boot 3 application: javax.servlet becomes jakarta.servlet, javax.persistence becomes jakarta.persistence, javax.validation becomes jakarta.validation and javax.annotation.PostConstruct becomes jakarta.annotation.PostConstruct. javax.sql.DataSource does not change, because it belongs to the JDK itself, not to Java EE.
What to remember
In this answer, we saw that the javax to jakarta rename applies only to Jakarta EE specification packages. So HttpServletRequest, Entity, NotNull and PostConstruct move to jakarta packages, while javax.sql.DataSource stays because it is part of the JDK. The rule is to ask where each package comes from, and to use migration tools rather than a blind search and replace.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Four of the five imports change in a Boot 3 application: javax.servlet becomes jakarta.servlet, javax.persistence becomes jakarta.persistence, javax.validation becomes jakarta.validation and javax.annotation.PostConstruct becomes jakarta.annotation.PostConstruct. javax.sql.DataSource does not change, because it belongs to the JDK itself, not to Java EE.
Why this question is asked
Every team moving from Boot 2 to Boot 3 meets the javax to jakarta rename in its first compile. Most of the time the rule is simple, but a few javax packages stay as they are, and replacing them blindly breaks the build. Interviewers ask this question to see whether we know where each package comes from, the JDK or the Jakarta EE specifications, because that is what decides whether it changes. In this answer, we will recap why the rename happened, go through each of the five imports, show the before and after code, and give a simple rule for the packages that stay.
1A Quick Recap of the Rename
Java EE was the set of enterprise specifications, such as Servlet, JPA and Bean Validation, that lived in packages starting with javax. When Oracle handed Java EE to the Eclipse Foundation, it kept the rights to the javax name. The new owners renamed the platform Jakarta EE, and from Jakarta EE 9 onwards every specification API moved from javax.* to jakarta.*. The classes and methods stayed the same; only the package name changed.
Spring Boot 3 is built on Spring Framework 6, which requires Jakarta EE 9 or later, so every library in a Boot 3 application must use the jakarta packages. Boot 4, on Spring Framework 7, moves on to Jakarta EE 11 but keeps the same jakarta names.
The JDK also has packages starting with javax, such as javax.sql, javax.crypto and javax.net. These were never part of Java EE. They belong to Java SE, the standard library that ships with every JDK, and they did not change.
2Going Through the Five Imports
For each import, we only need to ask one question: is this part of a Jakarta EE specification, or part of the JDK? The table answers it for our five imports.
| Boot 2 import | Boot 3 import | Comes from |
|---|---|---|
javax.servlet.http.HttpServletRequest | jakarta.servlet.http.HttpServletRequest | Jakarta Servlet |
javax.persistence.Entity | jakarta.persistence.Entity | Jakarta Persistence (JPA) |
javax.sql.DataSource | javax.sql.DataSource (unchanged) | JDK, module java.sql |
javax.validation.constraints.NotNull | jakarta.validation.constraints.NotNull | Jakarta Validation |
javax.annotation.PostConstruct | jakarta.annotation.PostConstruct | Jakarta Annotations |
HttpServletRequest comes from the Servlet specification, so it moves to jakarta.servlet. Entity comes from JPA, now called Jakarta Persistence, so it moves to jakarta.persistence. NotNull comes from Bean Validation, now Jakarta Validation, so it moves to jakarta.validation.
PostConstruct is the interesting one. In Java 8 it shipped inside the JDK, which is why many people think of it as a JDK class. It was removed from the JDK in Java 11 and now lives in the Jakarta Annotations specification, so in Boot 3 it is jakarta.annotation.PostConstruct. DataSource lives in the JDK's java.sql module, which has nothing to do with Jakarta EE, so it stays javax.sql.DataSource.
3The Code Before and After
Here is a small class that uses all five types, first as it looked in Boot 2.
Notice that the class bodies do not change at all. @Entity, @NotNull and @PostConstruct are used exactly as before, and HttpServletRequest has the same methods. That is why most of this migration can be done by tools such as the OpenRewrite Jakarta recipe or an IDE's migration action.
But there is a catch with search and replace. If we replace every javax. with jakarta., the line import javax.sql.DataSource becomes import jakarta.sql.DataSource, and that package does not exist. The compiler reports an error such as package jakarta.sql does not exist, which is easy to fix, but it shows why the replacement must be limited to the Jakarta EE packages.
4A Rule for the Packages That Stay
The JDK packages that keep their javax name include javax.sql, javax.crypto, javax.net and javax.net.ssl, javax.naming, javax.security.auth, javax.management, javax.xml.parsers and javax.transaction.xa. A quick way to check any import is to look for it in the JDK's own API documentation for our Java version: if it is there, it stays.
Watch out for one pair that looks similar. javax.transaction.xa.XAResource is in the JDK and stays, but javax.transaction.Transactional is from the Jakarta Transactions specification and becomes jakarta.transaction.Transactional. Most Spring code uses Spring's own org.springframework.transaction.annotation.Transactional, which never had a javax name.
5Follow-up questions
What happens if a dependency still uses javax.persistence?
It usually still compiles, if the old javax.persistence-api jar is on the classpath, but Hibernate 6 only looks for jakarta.persistence annotations. The entities in that library are ignored and we see errors such as Not a managed type at startup, or tables that are never mapped. The library needs a Jakarta version.
Is there a tool to do the rename for us?
Yes. OpenRewrite has a recipe that migrates javax to jakarta and the other Boot 3 changes, IntelliJ IDEA has a Migrate Packages and Classes action, and the Eclipse Transformer can rewrite compiled jars. All of them know which javax packages belong to the JDK and leave those alone.
Did the jakarta names stay the same in Boot 4?
Yes. Boot 4 moves to Jakarta EE 11, which changes some specification versions, such as Servlet 6.1 and Persistence 3.2, but the package names remain jakarta.*. There is no second rename.
6Conclusion
In this answer, we saw that the javax to jakarta rename applies only to Jakarta EE specification packages. So HttpServletRequest, Entity, NotNull and PostConstruct move to jakarta packages, while javax.sql.DataSource stays because it is part of the JDK. The rule is to ask where each package comes from, and to use migration tools rather than a blind search and replace.
Open with
In a Boot 3 application four of those five imports change. HttpServletRequest moves to jakarta.servlet.http, Entity moves to jakarta.persistence, NotNull moves to jakarta.validation.constraints, and PostConstruct moves to jakarta.annotation. javax.sql.DataSource stays exactly as it is.
Then, if they want more
The reason is where each type comes from. Boot 3 is on Spring Framework 6 and Jakarta EE 9 or later, and Jakarta EE renamed all the former Java EE specification packages from javax to jakarta after the move to the Eclipse Foundation.
DataSource was never Java EE; it is part of the JDK in the java.sql module, like javax.crypto or javax.net, so it keeps its name. PostConstruct is the one people get wrong, because it shipped with the JDK up to Java 8, but it was removed in Java 11 and now lives in Jakarta Annotations.
So I would not do a blind search and replace of javax with jakarta, because it would produce jakarta.sql, which does not exist. I would use the OpenRewrite migration recipe or the IDE's migration, which leave JDK packages alone, and then check dependencies for libraries that still use javax.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Jakarta EE 11, Jakarta EE 9, Hibernate 6, Java 11
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Which of these imports change in a Boot 3 application...": https://scrivio-interview-library.netlify.app/spring-boot/boot-migrations/c38a4dcf35/