找不到元素'context:annotation-config'的声明 [英] no declaration can be found for element 'context:annotation-config'
问题描述
在春天,每当我在spring.xml中写入<context:annotation-config/>
时,都会出现此错误:-
in spring whenever i write <context:annotation-config/>
in my spring.xml i get this error:-
线程主"中的异常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源[spring.xml]的XML文档中的第81行无效;嵌套的异常是org.xml.sax.SAXParseException; lineNumber:81; columnNumber:30; cvc-complex-type.2.4.c:匹配的通配符很严格,但是找不到元素'context:annotation-config'的声明.
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 81 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 81; columnNumber: 30; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
而我的spring.xml的内容是
And the content of my spring.xml is
<?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-4.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
>
<bean id="circle" class="com.mysite.Circle">
</bean>
...
<context:annotation-config/>
谁能告诉我我要去哪里错了吗??
Would anyone please tell me where am i going wrong ????
推荐答案
您正在使用XML命名空间(在这种情况下为上下文)而未声明
You are using an XML namespace (in this case context) without declaring it
将您的xml更改为此:
Change your xml to this:
<?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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
您还引用了 http://www.springframework.org/schema/beans/spring -beans-4.0.xsd ,我认为它不存在.
You were also referencing http://www.springframework.org/schema/beans/spring-beans-4.0.xsd, which I don't think exists.
这篇关于找不到元素'context:annotation-config'的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!