Deploying Spring 5.X on Tomcat 10.X

Deploying Spring 5.x on Tomcat 10.x

TL;DR: Spring MVC 5 does not run on Tomcat 10 because of the package renaming from javax.* to jakarta.*.

After further research, I was able to find the answer to my question. Spring MVC 5 does not work on Tomcat 10. This is because Tomcat 10 is based on Jakarta EE 9 where package names for APIs have changed from javax.* to jakarta.*.

Tomcat 10 mentioned this on the download webpage:

Users of Tomcat 10 onwards should be aware that, as a result of the
move from Java EE to Jakarta EE as part of the transfer of Java EE to
the Eclipse Foundation, the primary package for all implemented APIs
has changed from javax.* to jakarta.*. This will almost certainly
require code changes to enable applications to migrate from Tomcat 9
and earlier to Tomcat 10 and later.

For Spring MVC 5, the Spring MVC DispatcherServlet has a dependency on the javax.servlet.* package namespace. This is using the Java EE 8 javax package naming. Since Tomcat 10 is based on Jakarta EE 9, the packages for javax naming are not supported. This explains why Spring MVC 5 does not work on Tomcat 10.

There are GitHub issues filed against the Spring Framework regarding this:

Spring core 5 is not starting on Tomcat 10

Support for Jakarta EE 9 (annotations and interfaces in jakarta.* namespace)

In my case, instead of migrating to Tomcat 10, I will stay on Tomcat 9 until the Spring framework is upgraded to Jakarta EE 9.

Existing Spring boot application to Tomcat 10

No version of Spring at this time (neither Spring 5.3.x nor Spring Boot 2.5.x) supports Jakarta EE 9.

According to this issue ticket, you need to wait for Spring 6.x (2022) and Spring Boot 3.x.

Edit: It is official (cf. Spring blog): support for Jakarta EE 9 will be available in Spring Boot 3 and Spring 6, but at the same time they will require Java 17.

Edit2: The first milestone releases (3.0.0-M3 at the time of writing) are available in the Maven repository https://repo.spring.io/ui/native/milestone.

Why is upgrading to Tomcat 10.0.5 causing spring boot to shutdown after boot?

Tomcat 10 is a Jakarta EE 9 servlet container. It basically means, that all javax.* packages were renamed to jakarta.* for copyright reasons (Oracle didn't allow the Eclipse Foundation to use the javax.* names).

Spring Boot 2 and Spring 5 support only the previous Java EE 8 specification, you need to wait for Spring Boot 3 and Spring 6 for Tomcat 10 support. Alternatively you can pass Spring libraries through the Apache Tomcat Migration Tool, which just reached version 1.0 or downgrade to Tomcat 9.0.

See also

  • Tomcat 10.0.4 doesn't load servlets (@WebServlet classes) with 404 error

Hi I am trying to deploy spring mvc project in tomcat 10 but I am getting following error . I search a lot but not find the solution

Your jar file contains duplicate entries which probably cause problems when being deployed. If you run the following command with your jar file you will see the duplicate entries:

    $ unzip -l URWAYPGService.war |grep META 


Related Topics



Leave a reply



Submit