Spring MVC Maven登录注册项目404错误排查:Tomcat版本及依赖库更新影响咨询与解决方案请求
Hey there, let's break down your Spring MVC login/register flow issue step by step—this is a common pitfall with version mismatches and configuration gaps.
Your Context
I’m trying to understand and clone a Spring MVC login/register flow. I’ve fully followed the original code and process, only modifying database configuration, and can successfully insert data into MySQL 8.0.27 via test files. However:
- Initially, the form’s
actionthrew an error: element loginProcess is not found, which I fixed by adjusting the form action. - Now I’m still hitting a 404 error:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
My questions:
- Could using Apache Tomcat 10.0.13 cause this issue?
- Did updating dependencies with a new Eclipse version trigger this problem?
- What specific fixes can I apply?
Key Troubleshooting Steps & Fixes
1. Tomcat Version Compatibility (Critical!)
Yes, Tomcat 10.x is almost certainly a major factor here. Here’s why:
- Tomcat 10 switched from Java EE APIs (e.g.,
javax.servlet.*) to Jakarta EE APIs (e.g.,jakarta.servlet.*). - The original Spring MVC project you cloned is built for Java EE, so it won’t work natively with Tomcat 10—this is a breaking change that causes request mapping failures and 404s.
Fix Options:
- Downgrade to Tomcat 9.x: This is the fastest, lowest-effort fix. Tomcat 9 is fully compatible with Spring 5.x (the version used in most older MVC projects) and Java EE APIs.
- Migrate to Jakarta EE (Advanced): If you want to stick with Tomcat 10, you’ll need to upgrade the project to Spring Framework 6.x/Spring Boot 3.x, which support Jakarta EE. This requires replacing all
javax.servletimports withjakarta.servletand updating all related dependencies.
2. Dependency Version Mismatches
Updating dependencies in Eclipse can introduce silent conflicts, especially if the original project relies on specific Spring versions.
Check & Fix:
- Verify your
pom.xml(Maven) orbuild.gradle(Gradle) matches the original project’s dependency versions. For example, the original project likely uses Spring 5.x, which doesn’t support Jakarta EE. - Avoid mixing Spring Framework versions (e.g., don’t pair
spring-core 5.3.xwithspring-webmvc 6.x). - Ensure the MySQL 8.0.27 driver is explicitly included with the correct version:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.27</version> </dependency>
3. Request Mapping & Form Action Alignment
Even after fixing the initial action error, double-check these details:
- The form’s
actionmust exactly match the@RequestMappingvalue in your controller. For example, if your controller has:
Your form should use the context path to avoid deployment context issues:@RequestMapping(value = "/loginProcess", method = RequestMethod.POST)<form action="${pageContext.request.contextPath}/loginProcess" method="post"> - Always prepend
${pageContext.request.contextPath}to the action—this ensures the request targets your app’s context, even if it’s deployed under a non-root path.
4. Dispatcher Servlet Configuration
Ensure your web.xml (or Java-based config) correctly maps the Dispatcher Servlet to handle all requests:
- In
web.xml, confirm this section is present and correct:<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> - If using Java config, verify your
DispatcherServletRegistrationBeanis set up with the"/"URL pattern.
5. Deployment Cleanup
- In Eclipse, go to the Servers tab, right-click your Tomcat server, and select Clean to clear cached deployment files. Then restart the server.
- Check Tomcat’s
webappsfolder to ensure your application’s WAR file is unpacked correctly (no missing files or corrupted directories).
Quick Validation Test
- First, downgrade to Tomcat 9.x—this will rule out the biggest compatibility issue.
- Redeploy the original GitHub code (only updating DB config) and test the login/register flow.
- If it works, apply your custom changes incrementally to avoid breaking the flow.
内容的提问来源于stack exchange,提问作者Krishna Dubey

