Wednesday, March 20, 2013

Spring schemaLocation fails

I used to get this error
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '/spring-beans-3.1.xsd'…

Basically, it is because wrong version of jar files were in classpath.

Spring handles the schemas by “META-INF/spring.handlers” and “META-INF/spring.schemas”. As long as the correct version spring jar file in classpath, there should not be any problem.



Here is another quick workaround.



As all schema files were packaged in spring jar file. It should be able to find it from the classpath.



The key is the spring-context-3.1.xsd. The setting below works for me and I only set the context xsd from the classpath.



 



<beans xmlns="http://www.springframework.org/schema/beans"


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


    xmlns:context="http://www.springframework.org/schema/context"


    xmlns:jee="http://www.springframework.org/schema/jee"


    xmlns:aop="http://www.springframework.org/schema/aop"


    xmlns:tx="http://www.springframework.org/schema/tx"


    xsi:schemaLocation="


http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd


http://www.springframework.org/schema/context classpath:org/springframework/beans/factory/xml/spring-context-3.1.xsd

http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd


http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd


http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">



Here is an article from internet about this topic.

No comments:

Post a Comment