schema_reference.4:无法读取模式文档' http://www.springframework.org/schema/beans/spring- beans- 4.1.5.xsd

时间:2015-03-15 17:04:50

标签: spring web.xml

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

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

9 个答案:

答案 0 :(得分:23)

错误是因为找不到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">

答案 1 :(得分:3)

来自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依赖版本中正确识别   项目。另外,另一个优点是你可以升级Spring   您正在使用的版本,以及新的定义规范   没有你的配置文件自动支持   必须修改它们

答案 2 :(得分:2)

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

Spring 4.1s for Spring 4.1.x可以通过以下方式引用: 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 :(得分:2)

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

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

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

答案 4 :(得分:1)

不管你不相信,如果你正在使用它,这可能是一个maven问题,事情就像这样从无到有。我知道这可能不是你的情况,但如果是这样,请更新你的maven项目。 如果您正在使用Eclipse IDE:

  1. 右键单击项目名称。
  2. 的Maven。
  3. 更新项目......
  4. 同样,可能成为您的理由。这对我来说很有用。这也适用于处于相同情况的任何其他人。

答案 5 :(得分:0)

试试这个,它对我有用

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

答案 6 :(得分:0)

我已经为udemy参加了春季课程。我按照我的导师告诉我要做的每一步。 因此,如果您使用的是spring mvc和hibernate,则可能会遇到此错误 无法读取架构文档“http://www.springframework.org/schema/tx/spring-tx.xsd”等:

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

在我的弹簧配置文件中,我有这两个网址

    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,如上所示。

在我看来,明确指定版本是一个很好的做法。 它对我有用,希望这也适合你。 谢谢。

答案 7 :(得分:0)

我尝试按照其他解决方案中所述修改xml,但是没有一个对我有用。最后,我尝试在Web浏览器上打开架构位置文件,但是它也无法连接(即使Internet运行正常)。 Spring框架服务器停机了吗?

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

答案 8 :(得分:0)

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

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

因此它可能是您的应用程序中缺少类似的依赖项或 spring jar

相关问题