22

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.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
IM_Pub
  • 223
  • 1
  • 2
  • 5

4 Answers4

12

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.

Phil Webb
  • 8,119
  • 1
  • 37
  • 37
  • 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 01 '22 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 '23 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 '23 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 '23 at 02: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 '23 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.

Maik
  • 310
  • 1
  • 11
0

When upgrading to SpringBoot 3, Toncat 10 or anything that requires Jakarta EE 9, it’s always safer to replace all javax dependencies with jakarta ones. It’s not completely straightforward but you can automate it with Eclipse Transformer or similar tools.

If your application compiles OK, then I recommend running the final JAR or WAR through the Transformer. I explain how to do it in this blog: Upgrade To Jakarta EE 10: Transform Applications With Eclipse Transformer

OndroMih
  • 7,280
  • 1
  • 26
  • 44