【问题标题】:Getting error message with spring "cvc-elt.1: Cannot find the declaration of element 'beans'."使用spring“cvc-elt.1:找不到元素'beans'的声明”获取错误消息。
【发布时间】:2012-04-28 07:09:39
【问题描述】:

我正在尝试设置一个简单的 Spring 应用程序,但遇到了以下异常。这是在 eclipse indigo 中独立运行的。

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Line 2 in XML document from class path resource [context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)

这是我的代码的初始部分:

public static void main(String[] args) {

        try {

            BeanFactory beanfactory = new ClassPathXmlApplicationContext(
                    "context.xml");


            FirstBean bean = (FirstBean) beanfactory.getBean("show");

这是我的 context.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"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="anotherBean" class="AnotherBean" />
<bean id="show" class="FirstBean">
<constructor-arg ref="anotherBean" />
</bean>
<bean id="populateFD" class="PopulateFactData">
<constructor-arg value="localhost" />
<constructor-arg value="3309" />
</bean>
</beans>

【问题讨论】:

  • 你用的是哪个版本的spring jar?

标签: java eclipse spring


【解决方案1】:

【讨论】:

    【解决方案2】:

    当我在 STS 中遇到这个问题时,我刚刚清理了项目并且它工作了。

    【讨论】:

    • 但是当你做 maven -> 更新项目时它会回来。
    【解决方案3】:

    maven shade 插件似乎替换了 jar 中的 spring.schemas 文件,因此使用每个 jar 中的所有单独的 spring.schema 内容创建我们自己的一个应该可以解决问题。

    【讨论】:

      【解决方案4】:

      您确定在类路径中有spring-beans

      这个错误通常意味着它找不到一个spring.schemas(在spring-beans.jar中)向它解释这个命名空间的含义。

      其他选项是 Maven Shade 插件已损坏 spring.schemas,但由于您没有提到 Maven,因此不太可能出现这种情况。

      【讨论】:

      • 这是一个 jar/类路径问题。我正在使用附带教程的一小组弹簧罐。在我从 springsource 下载完整包并将这些 jar 添加到我的构建路径后,错误就消失了。
      【解决方案5】:

      也许这篇文章可以帮助你:

      Cannot find the declaration of element 'beans' in internet offline mode

      好像是Schema配置的问题。

      【讨论】:

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