IDEA/servlet/DispatcherServlet/ tomcat10 404
-
问题描述:
IDEA下部署SpringMVC项目,pom.xml中使用servlet依赖,web.xml中配置servlet-class为:org.springframework.web.servlet.DispatcherServlet,使用tomcat10访问页面出现404,使用tomcat9/8访问正常
-
原因:
-
SpringMVC DispatcherServlet依赖于javax.servlet.*命名空间
-
上述Javax包基于JavaEE8。但Tomcat10是基于JakatraEE9,其中包从javax.* 重命名为jakarta.*
Tomcat 10 在 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.*
tojakarta.*
. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
-
-
解决方案
- 自己写控制器类改变包的引用
- 将tomcat从10降为9/8等低版本
ref:
java - 在 Tomcat 10 上部署 Spring MVC 5 … 部署问题 - IT工具网 (coder.work)