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 fromjavax.*
tojakarta.*
. 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
Java Byte Array to String to Byte Array
Java Simpledateformat("Yyyy-Mm-Dd'T'Hh:Mm:Ss'Z'") Gives Timezone as Ist
How to Restart a Java Application
Converting Symbols, Accent Letters to English Alphabet
Using Heapdumponoutofmemoryerror Parameter for Heap Dump for Jboss
How to Get Java 11 Run-Time Environment Working Since There Is No More Jre 11 for Download
Call an Executable and Pass Parameters
Controlling Maven Final Name of Jar Artifact
Bounding Generics with 'Super' Keyword
What Is the Java's Internal Represention for String? Modified Utf-8? Utf-16
How to Achieve Method Chaining in Java
Getting the Text That Follows After the Regex Match
Importing Two Classes with Same Name. How to Handle