[英]Getting error message with spring “cvc-elt.1: Cannot find the declaration of element 'beans'.”
I'm trying to set up a simple spring application and I'm getting the below exception. 我正在尝试设置一个简单的spring应用程序,我得到以下异常。 This is being run standalone in eclipse indigo.
这是在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)
Here's the initial portion of my code: 这是我的代码的初始部分:
public static void main(String[] args) {
try {
BeanFactory beanfactory = new ClassPathXmlApplicationContext(
"context.xml");
FirstBean bean = (FirstBean) beanfactory.getBean("show");
Here's my context.xml file: 这是我的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>
Are you sure you have spring-beans
on the classpath? 你确定你在classpath上有
spring-beans
吗?
This error normally means that it can't find a spring.schemas
(which is in spring-beans.jar
) explaining to it what that namespace means. 此错误通常意味着它找不到
spring.schemas
(在spring-beans.jar
)向它解释该命名空间的含义。
Other options are that the Maven Shade plugin has damaged spring.schemas
, but that's unlikely to be the case as you haven't mentioned Maven. 其他选项是Maven Shade插件损坏了
spring.schemas
,但由于你没有提到Maven,所以情况不太可能。
Maybe this post can help you: 也许这篇文章可以帮助你:
Cannot find the declaration of element 'beans' in internet offline mode 在互联网离线模式下找不到元素'beans'的声明
It seems like being a problem of Schema configuration. 这似乎是Schema配置的问题。
maven shade插件似乎取代了jar中的spring.schemas文件,因此使用每个jar中的所有单独的spring.schema内容创建我们自己的一个应该可以解决问题。
当我在STS中遇到这个问题时,我刚刚清理了项目并且它有效。
There could be possibility of mismatch of Spring Bean version and xsd definition. 可能存在Spring Bean版本和xsd定义不匹配的可能性。
For Example beans xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 例如bean xsi:schemaLocation =“http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework。 org / schema / mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema /beans/spring-beans-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http:// www。 springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema /context/spring-context-3.0.xsd
While in spring version is 3.0.5-Release 而春季版则是3.0.5-Release
Check classpath version and keep them same. 检查类路径版本并保持相同。 Shoul
建议立即进行删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.