【问题标题】:Spring Configuration Error: (cvc-etl.1)弹簧配置错误:(cvc-etl.1)
【发布时间】:2012-07-05 03:19:18
【问题描述】:

我尝试了所有我能想到的方法,但似乎没有任何效果。

我在我的 java web 应用程序中使用当前版本的Spring Framework (3.2)。 每次我开始我的项目时,我都会收到以下错误:

cvc-elt.1: 找不到元素“beans”的声明

这是我的 applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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"

</beans>

我试过了:

  1. 更改架构的版本(3.2、2.0...)
  2. 将模式从 jar 复制到 WEB-INF
  3. 将 unix EOL 更改为 windows EOL

除了使用 DTD 声明而不是 XSD 之外,似乎没有任何效果。 我该怎么办?

【问题讨论】:

    标签: java spring jsp


    【解决方案1】:

    Spring 无法找到 xsd。看看this SO post。如果您确定您的类路径中有所需的 spring-beans jar,则您的 META-INF/spring.schemas 文件可能已损坏。 spring.schemas 文件告诉 spring 使用哪个类路径在 spring jar 中找到相应的 xsd 文件。我在使用配置不正确的 maven-shade 插件时发生了这种情况。

    【讨论】:

      【解决方案2】:

      当我将 xsd 粘贴到浏览器中时,它对我来说很好。

      这个对我来说很好用:

      <?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"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd">
      
          <context:annotation-config/>
          <context:component-scan base-package="example"/>
      
      </beans>
      

      【讨论】:

      • 我的电脑没有连接到互联网,所以我不能运行这个测试
      猜你喜欢
      • 2010-09-20
      • 1970-01-01
      • 2011-09-11
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多