【问题标题】:cvc-elt.1: Cannot find the declaration of element 'beans' - applicationcontext.xmlcvc-elt.1:找不到元素“beans”的声明 - applicationcontext.xml
【发布时间】:2015-12-19 16:55:24
【问题描述】:

我最终只得到这个错误: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源 [applicationContext.xml] 的 XML 文档中的第 12 行无效;嵌套异常是 org.xml.sax.SAXParseException; cvc-elt.1:找不到元素“beans”的声明。 我看到已经存在 bean 的声明

谁能帮我解决我到底哪里出错了?

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" 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-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/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">

<mvc:annotation-driven>
</mvc:annotation-driven>

目前的 Spring jar 是 4.1.6。

【问题讨论】:

  • 缺少一个>
  • 要是这么简单就好了。这是我从外部机器粘贴的错误副本。它在源代码中确实有一个 > ,但我仍然得到同样的错误。谢谢你在这里捕捉到。我将编辑问题
  • 你能告诉我们至少 12 行吗?错误似乎发生在第 12 行
  • @Alexandre Jacob:我刚刚用 applicationContext 文件更新了我的问题。如果您发现任何问题,请告诉他们

标签: spring applicationcontext


【解决方案1】:

这是您更正后的文件:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" 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-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/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">

<mvc:annotation-driven>
</mvc:annotation-driven>
</beans>

你写的是xsi:schemalocation而不是xsi:schemaLocation(注意大写L

【讨论】:

    【解决方案2】:

    更多关于xsi:schemaLocation的信息:

    XML 解析器将从 Internet 读取架构位置并使用它来验证 xml。如果您没有互联网访问权限(就像大多数没有互联网访问权限的生产系统一样),Spring 会来救援。它解释读取请求并从 Spring jar 中加载模式。

    【讨论】:

      猜你喜欢
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2020-05-08
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多