18

In the new Spring boot 3 Release notes, They tells that this version is going to use Jakarta EE 9 (libs named as jakarta) instead of JEE (libs named as javax).

They advise developers to replace imported javax with jakarta in this article.

If I have a spring boot app with both, javax and jakarta libs, will the app work and be able to be deployed in a Jakarta compatible server (e.g. Tomcat 10)?

Thanks a lot.

3 Answers 3

11

The answer will really depend on which specific libraries you're using and how they interact with each other, but generally speaking trying to mix Java EE and Jakarta EE them would be a bad idea.

As an example, if you're writing a Spring MVC application then you'll be using the DispatcherServlet. In Spring Framework 6 this will require the Jakarta Servlet API. There's not going to be a way to make it work with the javax.servlet For other APIs, if you're using them directly and you're not making use of Spring abstractions that build on them, you may get away with having them on your classpath. I still wouldn't recommend it.

5
  • Thanks a lot. Actually we got some internal libraries they use javax. They only way to stick with spring boot 3 and jakarta is to migrate all these libs + the main app to Jakarta.
    – IM_Pub
    Mar 1, 2022 at 15:11
  • @Phil Webb jakarta.persistence-api does not appear to have a replacement for javax.sql.DataSource or javax.persistence.EntityManagerFactory. Do you know how to address this?
    – Bradley D
    Jan 14 at 23:59
  • 1
    @BradleyD javax.sql.DataSource is part of the JDK and still uses the javax package. ` jakarta.persistence-api-3.1.0` contains jakarta.persistence.EntityManagerFactory.
    – Phil Webb
    Jan 18 at 19:21
  • @Phil Webb Once I removed the JPAConfig class, removed all unnecessary dependencies one by one, and added the following to application.properties, i was good to go! spring.datasource.url=${jdbc.url} spring.datasource.username=${jdbc.username} spring.datasource.password=${jdbc.password} spring.datasource.driverClassName=${jdbc.driverClassName}
    – Bradley D
    Jan 19 at 2:46
  • @Phil Webb there is lot of changes in Jakarta. I am facing lot of problem after this upgrade. Example I am using 3 entity classes one is parent entity and other two are child for parent. When Using many to one annotations and Saving values to child entity also.. But the foreign key from parent entity is not reflected in child entity . However I tried many way till its not working.. Any one knows solution for it update me...
    – Santil
    Feb 11 at 10:49
1

In case it helps anyone, I can confirm the issue.

To deal with security vulnerabilities I updated my POMs from Spring 5.3.15 to 6.0.6 and Spring Security 5.6.1 to 6.0.2.

The very first issue I found was that HttpServletRequest is no longer compatible, at least if you are extending AbstractAuthenticationProcessingFilter and probably much more.

Base on this and other threads it very much seems that the solution is to replace javax.servlet-api with jakarta.servlet-api and update all of the impacted imports.

0

You could try to put the web app instead of in webapps into webapps-javaee like described in https://tomcat.apache.org/migration-10.html#Specification_APIs

Then TC10 will create a new war in webapps and unpack it as usual in webapps. I tried it with some of our pure TC8/9 Apps and it was working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.