🚀 A beginner’s survival guide to making Spring MVC work with XML configuration in 2024–25.
📌 Background
As a student and Java learner, I decided to build a Spring MVC project using Spring 6.2.7 with XML configuration (web.xml
, springDispatcherServlet-servlet.xml
, etc.).
But it wasn't easy! I ran into multiple errors—schema failures, prefix binding issues, Tomcat errors—almost everything a beginner could face.
In this post, I’m sharing each error I faced and how I fixed it, so you don’t waste hours the way I did.
❌ 1. schema_reference.4
and cvc-elt.1.a
Errors
❗ Error:
schema\_reference.4: Failed to read schema document '[http://www.springframework.org/schema/beans/spring-beans.xsd](http://www.springframework.org/schema/beans/spring-beans.xsd)'... cvc-elt.1.a: Cannot find the declaration of element 'beans'
`
✅ Fix: Use HTTPS URLs for schema declarations
Replace the HTTP links with HTTPS in the <beans>
header:
xml
<beans xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:context="https://www.springframework.org/schema/context"
xmlns:mvc="https://www.springframework.org/schema/mvc"
xsi:schemaLocation="
https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
https://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
`
💡 Spring 5.3+ supports only HTTPS schema resolution from the classpath.
❌ 2. The prefix "mvc" for element "mvc:annotation-driven" is not bound
❗ Error:
`xml
<mvc:annotation-driven/>
`
Gives:
`
The prefix "mvc" for element "mvc:annotation-driven" is not bound.
`
✅ Fix: Add xmlns:mvc
and its schema location
Make sure this is added in your XML:
`xml
xmlns:mvc="https://www.springframework.org/schema/mvc"
`
And in xsi:schemaLocation
:
`xml
https://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
`
❌ 3. Tomcat Error: The requested resource [/springMVC/] is not available
✅ Fix checklist:
- Check if
web.xml
contains correct servlet mapping:
`xml
springDispatcherServlet
org.springframework.web.servlet.DispatcherServlet
1
springDispatcherServlet
/
`
Ensure correct location:
YourspringDispatcherServlet-servlet.xml
must be inside/WEB-INF/
Project must be built correctly and deployed properly to Tomcat.
❌ 4. Cannot invoke "Object.hashCode()" because "key" is null
in Jakarta Tomcat
✅ Fix:
- Double-check
web.xml
mapping. -
Use compatible versions of:
- Spring 6+
- Jakarta EE 10+
- Tomcat 10+
Mixing old versions causes reflection or namespace binding failures.
❌ 5. External Schema Download Disabled
If you're behind a proxy or working offline, Eclipse/STS cannot fetch .xsd
files online.
✅ Fix Options:
- Use HTTPS URLs so Spring resolves schemas from its own JAR files
- Or: Add a manual mapping in Eclipse → XML Catalog
- Or: Disable XML validation temporarily from Project → Properties → Validation
💡 Key Lessons I Learned
- ✅ Always use HTTPS URLs for all Spring XML schemas.
- ✅ Ensure schemaLocation URLs are on the same line (Eclipse hates broken lines).
- ✅ Use consistent and compatible Spring versions (don’t mix Spring 5 with 6).
- ✅ Prefer annotation-based config long-term—but mastering XML helps debug legacy code!
🧠 Final Thoughts
Dealing with XML in Spring MVC might feel outdated, but it's still worth understanding. Many enterprise projects still use XML config.
By solving these issues step-by-step, I learned how Spring’s internal schema resolution works, how Tomcat processes web.xml
, and how to troubleshoot like a real developer.
🗨️ Have you faced similar XML issues while learning Spring?
Leave a comment and let's connect!
Top comments (0)