schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-4.1.5.xsd - spring

I get an error in spring-dispatcher.xml in eclipse as given below.
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-
beans-4.1.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
element of the document is not <xsd:schema>.
I have latest spring libraries...
spring-beans-4.1.5.RELEASE.jar
spring-beans-4.1.5.RELEASE-javadoc.jar
spring-beans-4.1.5.RELEASE-sources.jar
spring-context-4.1.5.RELEASE.jar
spring-context-4.1.5.RELEASE-javadoc.jar
spring-context-4.1.5.RELEASE-sources.jar
spring-context-support-4.1.5.RELEASE.jar
spring-context-support-4.1.5.RELEASE-javadoc.jar
spring-context-support-4.1.5.RELEASE-sources.jar
spring-webmvc-4.1.5.RELEASE.jar
spring-webmvc-4.1.5.RELEASE-javadoc.jar
spring-webmvc-4.1.5.RELEASE-sources.jar
spring-webmvc-portlet-4.1.5.RELEASE.jar
spring-webmvc-portlet-4.1.5.RELEASE-javadoc.jar
spring-webmvc-portlet-4.1.5.RELEASE-sources.jar
spring-dispatcher.xml as given below...
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
It would be great if I get some help... The posts with same subject did not help me to resolve this.Thanks in advance...

The error is because it could not find the xsd. Try doing the below which is using a specific version 4.1.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
Or if you don't mention a version, it will try to use the latest.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

From Cosmina I. - Pivotal Certified Professional Spring Developer Exam A Study Guide - 2017
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
A recommended (best) practice is to use this, since the version will
be correctly identified from the Spring dependency version in the
project. Also, the other advantage is that you can upgrade the Spring
version you are using, and the new definition specifications will be
automatically supported in your configuration files without your
having to modify them

There is no such xsd in any Spring jar :
http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd
Spring xsd for Spring 4.1.x can be referenced by :
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
or better :
http://www.springframework.org/schema/beans/spring-beans.xsd
The correspondance between the URL and the real location inside each spring jar can be found in META-INF/spring.schemas, so the "version less" URL will still work when u upgrade Spring.

In my case it went away by adding
<?xml version="1.0" encoding="utf-8"?>
to spring-dispatcher.xml and then running update maven project.

Belive me or not, this may be a maven problem if you're using it and things ended up like this from nothing. I know this may not be your case, but if so, please update your maven project. If you're using Eclipse IDE:
Right click on the project name.
Maven.
Update Project...
Again, this may be your case. It worked for me doing this. This can work also to anybody else who is on the same situation.

Try this, it worked for me
<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"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">

I have enroled for spring course on udemy. I followed every step that my instructor show me to do.
So if you are using spring mvc and hibernate you may encounter this error
Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd' etc for:
<mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" /> elements
in my spring configuration file i had these two urls
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
in xsi:schemaLocation, which i replaced with
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
Actually visit these two sites
http://www.springframework.org/schema/mvc/ and http://www.springframework.org/schema/tx/
and just added the latest version of spring-mvc and spring-tx i.e, spring-mvc-4.2.xsd and spring-tx-4.2.xsd as shown above.
In my opinion specifying version no explicitly is a good practice.
It worked for me, hope this works for you too.
Thank you.

I tried modifying the xml as mentioned in the other solutions but none of them worked for me. In the end I tried opening the schema location file on a web browser but it wouldn't connect either (even though internet was working fine). Was the spring framework server down?
Turns out the Internet Security software that we use had to be turned on to access this site. So try opening the schema file in a web browser to verify that the URL is correct and that you can connect to it especially if the configuration was working fine previously.

I had a similar problem, it was giving the similar error for http://mybatis.org/schema/mybatis-spring.xsd file. Finally it was a missing jar in the application. I added the below dependency in my gradle file and that solved the problem
compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0'
So it could be a similar dependency or a spring jar missing in your application

Using Version-less dependencies is appreciated. Find my code below.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean "class name goes here"> </bean>
</beans>

Related

Upgrading spring to 5.0.9

I am trying to bump up Spring from version 4.3.14 to 5.0.9. Here's what my beans specification looks like:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
I do not see a XML schema definition file for Spring 5 such as 'spring-context-5.0.xsd' at http://www.springframework.org/schema/context. Is version-less schema the only way to go for Spring 5? Or can I continue using the 4.3 version of xsd's?
You can use schema without version numbers.
[https://www.springframework.org/beans/spring-beans.xsd] Currently, it refers to 4.3, but there another link from suggests that with the 'versionless' schema, it would be updated to latest version.
Refer to these for more details:
https://jira.spring.io/browse/SPR-13499

Spring Updating Version

I'm trying to update spring from 3.2 to 4.1.6 version, I downloaded the jars and replace them with the old one.
The question is must I change the schemaLocation versions in the application-context.xml ?
If you don't have an exception and the application works then no.
If you have the schemas without the version:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
instead of
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
the framewrok will get the right schema.

SAXParseException, the root element of the document is not <xsd:schema>

Here is the header of my spring-security.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd ">
When starting the server, I am prompted this error :
org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document
'http://www.springframework.org/schema/security/spring-security-oauth2-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 <xsd:schema/>.
My thoughts on this :
The link is valid and the document exists
I can read it and I can even reproduce this error if I place this xsd on my local classpath. So it's not a networking issue.
That's right, the file is starting by <xs:schema> instead of <xsd:schema>. But the source looks legit.
Why do I get this error and how can I get rid of it ?
Change all your schema locations to use version-less URIs, those XSDs are embedded in Spring JARs.
Because you're using versioned links to XSDs, your application breaks if it can't find that particular version on classpath.
See this SO answer for more details.

Drools integrated with spring faced with a xsd not found warning

I'm using Spring+Drools in my Web Application.The following is the drools modules configuration
<?xml version="1.0" encoding="UTF-8"?>
<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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:drools="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://drools.org/schema/drools-spring
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd"
default-autowire="byName">
<drools:kbase id="kbase1">
<drools:resources>
<drools:resource type="DRL" source="classpath:uniteStickyRules.drl"/>
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession1" type="stateful" kbase="kbase1"/>
When I ran my application using this configuration in my junit project it worked, yet it came with the following problem when I startup my Web application. As a result, I couldnot find my kbase bean.
2012-03-29 12:55:48,402 WARN resolver.SpringPluggableSchemas - Could not find schema classpath:org/drools/container/spring/drools-service-spring.xsd for URI: http://drools.org/schema/drools-service-spring.xsd,
class path resource [org/drools/container/spring/drools-service-spring.xsd] cannot be resolved to URL because it does not exist
2012-03-29 12:55:48,413 WARN resolver.SpringPluggableSchemas - Could not find schema classpath:file:/C:/Users/Dan%20Diephouse/workspace/xfire/target/checkout/xfire-spring/target/test-generated/services.xsd for URI: http://xfire.codehaus.org/config/1.0,
class path resource [file:/C:/Users/Dan%20Diephouse/workspace/xfire/target/checkout/xfire-spring/target/test-generated/services.xsd] cannot be resolved to URL because it does not exist
You see, I didn't put the drools-service-spring.xsd in my .xml file. So I'm quite stuck with it. Any suggestions?

Where is the spring rabbit XSD (schema location for the rabbit: namespace)

http://static.springsource.org/spring-amqp/docs/1.0.x/reference/html/ mentions the rabbit: namespace, but never mentions what is the schema location. Googling (and naming conventions) ended up with:
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
but this files does not exist. So where is the xsd?
Today XML schema located at:
http://www.springframework.org/schema/rabbit/spring-rabbit-1.3.xsd
http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd
http://www.springframework.org/schema/rabbit/spring-rabbit-1.5.xsd
Pick any you need!
As a temporary solution, I'm using this schema location to enable autocomplete. Otherwise it is located in the spring-rabbit jar (but the IDE does not detect it):
That is (from a comment from stacker):
I have the following at the top of my schema declaration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
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
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/rabbit
https://raw.github.com/SpringSource/spring-amqp/master/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-1.0.xsd">
I confirm Bozho's solution.
So basically at the top of my schema declaration I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
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
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/rabbit
https://raw.github.com/SpringSource/spring-amqp/master/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-1.0.xsd">
Find a spring jar with META-INF/spring.schemas that has a reference to the rabbit xsd. The problem was resolved in my config by adding this maven dependency
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
or
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.1.1.RELEASE</version>
</dependency>
I know this question is older and my answer probably would not have worked at the time of the original question, but in case anyone happens on to this question after today...
The spring rabbit xsd is currently located here:
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
And to use it, you must have spring-rabbit-1.0.0.RELEASE.jar in your classpath.
It should be included in the AMQP jars. According to this thread you should use the snapshot version instead of RC1 and then you shouldn't receive any errors.

Resources