【问题标题】:schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-4.1.5.xsdschema_reference.4:无法读取架构文档'http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd
【发布时间】:2015-05-17 18:48:58
【问题描述】:

我在 Eclipse 中的 spring-dispatcher.xml 中遇到错误,如下所示。

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

我有最新的 spring 库...

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 如下所示...

<?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">

如果我能得到一些帮助会很棒...相同主题的帖子没有帮助我解决这个问题。提前致谢...

【问题讨论】:

    标签: spring web.xml


    【解决方案1】:

    错误是因为找不到 xsd。尝试执行以下使用特定版本 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">
    

    或者如果你没有提到版本,它会尝试使用最新的。

    <?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">
    

    【讨论】:

    • 强烈推荐使用无版本模式,见stackoverflow.com/questions/20894695/…
    • 我也遇到了类似的问题。我没有使用任何版本。效果很好。
    • 我遇到了同样的问题,这为我解决了。我正在使用 Netbeans。 :)
    • @HarshalPatil,不客气。任何可以帮助他人的事情。
    • 我有同样的问题,一旦我向 xsd 提到版本,它就得到了解决。谢谢小黄人!
    【解决方案2】:

    在任何 Spring jar 中都没有这样的 xsd: http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd

    Spring 4.1.x 的 Spring xsd 可以通过以下方式引用: http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 或更好 : http://www.springframework.org/schema/beans/spring-beans.xsd

    每个 spring jar 中的 URL 和实际位置的对应关系可以在 META-INF/spring.schemas 中找到,所以当你升级 Spring 时,“版本少”的 URL 仍然有效。

    【讨论】:

      【解决方案3】:

      在我的情况下,它通过添加

      消失了
      <?xml version="1.0" encoding="utf-8"?>
      

      到 spring-dispatcher.xml 然后运行更新 maven 项目。

      【讨论】:

      • 我在 之后添加
      【解决方案4】:

      信不信由你,如果您正在使用它,这可能是一个 maven 问题,而事情最终变成了这样。我知道这可能不是你的情况,但如果是这样,请更新你的 Maven 项目。 如果您使用的是 Eclipse IDE:

      1. 右键单击项目名称。
      2. 马文。
      3. 更新项目...

      同样,这可能是您的情况。这样做对我有用。这也适用于处于相同情况的任何其他人。

      【讨论】:

        【解决方案5】:

        来自 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
        

        推荐的(最佳)做法是使用它,因为该版本将 从 Spring 依赖版本中正确识别 项目。此外,另一个优点是您可以升级 Spring 您正在使用的版本,新的定义规范将是 在您的配置文件中自动支持,无需您的 不得不修改它们

        【讨论】:

          【解决方案6】:

          试试这个,它对我有用

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

          【讨论】:

            【解决方案7】:

            我已报名参加 udemy 的春​​季课程。我按照老师教我做的每一个步骤去做。 所以如果你使用spring mvc和hibernate你可能会遇到这个错误 无法读取架构文档“http://www.springframework.org/schema/tx/spring-tx.xsd”等:

            <mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" /> elements
            

            在我的 spring 配置文件中,我有这两个 url

                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
            

            在 xsi:schemaLocation 中,我将其替换为

                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
            

            实际访问这两个站点 http://www.springframework.org/schema/mvc/http://www.springframework.org/schema/tx/ 并且刚刚添加了最新版本的 spring-mvc 和 spring-tx,即 spring-mvc-4.2.xsd 和 spring-tx-4.2.xsd,如上所示。

            在我看来,明确指定版本号是一个好习惯。 它对我有用,希望这对你也有用。 谢谢。

            【讨论】:

              【解决方案8】:

              我尝试修改其他解决方案中提到的 xml,但没有一个对我有用。最后,我尝试在网络浏览器上打开架构位置文件,但它也无法连接(即使互联网工作正常)。 spring 框架服务器宕机了吗?

              原来我们使用的互联网安全软件必须开启才能访问该网站。因此,请尝试在 Web 浏览器中打开架构文件,以验证 URL 是否正确,并且您可以连接到它,尤其是在之前的配置工作正常的情况下。

              【讨论】:

                【解决方案9】:

                我遇到了类似的问题,它给http://mybatis.org/schema/mybatis-spring.xsd 文件提供了类似的错误。最后,它是应用程序中缺少的 jar。我在我的 gradle 文件中添加了以下依赖项并解决了问题

                compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0'
                

                所以它可能是一个类似的依赖或你的应用程序中缺少一个 spring jar

                【讨论】:

                  【解决方案10】:

                  感谢使用无版本依赖项。在下面找到我的代码。

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

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2012-09-01
                    • 2021-11-27
                    • 2015-11-01
                    • 2019-08-19
                    • 2014-12-04
                    • 2015-06-10
                    相关资源
                    最近更新 更多