Migrating from Spring 5 to Spring 6: unable to find classes in jakarta packages

138 Views Asked by At

I am migrating my project from spring 5 to spring 6 and springBoot to 3. Below are some imports of javax package that are not available in jakarta package.

please suggest where in spring 6 these classes are migrated or any alternative that I can use to replace javax classes

    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.PBEKeySpec;
    import javax.xml.datatype.*;
    import javax.xml.namespace.*;
    import javax.jms.*;
2

There are 2 best solutions below

0
Julius278 On BEST ANSWER

here is a list of unaffected packages (link). They are still javax also in Spring 6 / Spring Boot 3.

Oh.. I see your jms package is not included there.. but there is a new jakarta package for that, maybe try to migrate to this one

If there any more issues, (as M.Deinum already said) let us see your pom

and as Rohan already said, you will need at least Java 17 for Spring 6 / Spring Boot 3, but I'm pretty sure you're aware of that.

0
Dhanashree K. On

Spring 6 requires JDK 17 or above and tomcat 10.1.x to 10.1.18

javax.servlet dependency needs to be replaced by jakarta-servlet dependency.

You can use the following readymade openrewrite recipes and it does lot of tedious and required work for you.

Rather than plugins here the CLI commands for maven work as a charm.

Before commit have a look once on changes certain changes may be not required to be done now as are backward compatible like URL to URI.

Keep in note for Spring 6 your code must be JDK 17 min.jdk or above.(JDK migration recipes also available at this site https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-java-17 )

https://docs.openrewrite.org/recipes/java/migrate/jakarta/jakartaee10

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.jakarta.JakartaEE10

https://docs.openrewrite.org/recipes/java/spring/boot3

Along with that keep xmlns or xsd for spring xmls(without any version specification.) and web.xml as latest.

Keep in note that project existing dependencies may bring older spring versions you compulsory need to exclude to avoid them from coming in final package runtime of container else there will be spring errors for configuration. If using IDE keep it reindexing when updating maven dependencies.