Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用spring“获取错误消息”;cvc elt.1:找不到元素';豆子&引用;_Java_Eclipse_Spring - Fatal编程技术网

Java 使用spring“获取错误消息”;cvc elt.1:找不到元素';豆子&引用;

Java 使用spring“获取错误消息”;cvc elt.1:找不到元素';豆子&引用;,java,eclipse,spring,Java,Eclipse,Spring,我正在尝试设置一个简单的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

我正在尝试设置一个简单的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>

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


这似乎是架构配置的问题。

您确定类路径上有
Springbeans

这个错误通常意味着它找不到
spring.schemas
(在
springbeans.jar
中)解释名称空间的含义


其他选项是Maven Shade插件损坏了spring.schemas,但情况不太可能如此,因为您没有提到Maven。

Maven Shade插件似乎取代了JAR中的spring.schemas文件,因此,使用每个jar中的所有单个spring.schema内容创建一个我们自己的,应该可以解决这个问题。

当我在STS中遇到这个问题时,我刚刚清理了这个项目,它成功了。

可能存在Springbean版本和xsd定义不匹配的可能性

比如说 bean xsi:schemaLocation=”http://www.springframework.org/schema/aop

而在春季版本是3.0.5-Release


检查类路径版本并保持不变。您应该使用哪个版本的spring jar?这是一个jar/类路径问题。我使用的是一个教程附带的一小组spring jar。在我从springsource下载完整的软件包并将这些jar添加到我的buildpath后,错误消失了。但当您使用maven时,它又回来了->更新项目。