Solving Spring Schema not found issue

Few weeks back when we were testing a Mobicents application I came across a strange error from Spring.


Warning parsing XML: XML InputStream(68) schema_reference.4: Failed to
read schema document 'http://www.springframework.org/schema/beans/spring-beans-2.0.xsd',
because 1) could not find the document;
2) the document could not be read;
3) the root element of the document is not .


Application was working fine few hours before and I was wondering what could be the error. Later I found out that this error comes because I've unpluged the network cable, application worked fine when I plugged it back. It was seems to be that Spring is trying to download schemas from internet rather than using files in classpath. This was a serious issue because machines at production site do not have internet access.

After few hours of searching we found out that a way to tell spring to get schemas from class path rather than downloading. Just give classpath:schema location in Spring xml context file in the opening declaration instead of giving url http://www.springframework.org/schema/beans/spring-beans-2.5.xsd.


<beans schemalocation="http://www.springframework.org/schema/beans
classpath:org/springframework/beans/factory/xml/spring-beans-2.5.xsd"
xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans">

</beans>
 

Reader Comments

Thank you for the enlightening blog.

You can also achieve the same by copying spring.schemas from the spring distribution to your web applications WEB-INF directory.