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

10

23

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...

Jaggers answered 15/3, 2015 at 17:4 Comment(0)
R
30

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">
Rees answered 16/3, 2015 at 1:46 Comment(8)
Using version-less schemas is strongly recommended, see #20895195Arnettaarnette
I've got the similar problem. I didn't use any version. It worked fine.Juba
I had the same problem, this fixed it for me. I am using Netbeans. :)Izak
@HarshalPatil, You are welcome. Anything to help others.Rees
I have the same problem and it got solved once I mentioned the version to xsd. Thanks minion!Ripply
It works for me when you start the server while you have connected to internet.Lorielorien
Thanks, working fine for me. But a small mistake is here. Instead of xmlns:context="http://www.springframework/schema/context", it should be xmlns:context="http://www.springframework.org/schema/context".Interinsurance
Caused by: org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 67; Element type "beans" must be declared.Wallet
E
4

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

Ensign answered 14/5, 2017 at 16:47 Comment(0)
M
2

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.

Mezzorelievo answered 30/7, 2015 at 19:42 Comment(0)
F
2

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.

Fulvous answered 19/2, 2016 at 19:10 Comment(1)
I add <!DOCTYPE xml> after the <?xml...>Counterglow
W
2

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:

  1. Right click on the project name.
  2. Maven.
  3. 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.

Whaleboat answered 10/3, 2017 at 17:19 Comment(0)
E
0

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">
Endocarp answered 28/9, 2017 at 13:28 Comment(0)
E
0

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.

Eyelid answered 15/11, 2017 at 17:16 Comment(0)
P
0

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.

Pahlavi answered 7/11, 2019 at 10:41 Comment(0)
C
0

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

Concave answered 4/3, 2021 at 6:58 Comment(0)
T
0

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>
Trine answered 26/1, 2022 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.