gpt4 book ai didi

xml - 找不到元素 'context:annotation-config' 的声明

转载 作者:IT老高 更新时间:2023-10-28 13:47:24 27 4
gpt4 key购买 nike

Spring ,每当我写 <context:annotation-config/>在我的 spring.xml 中,我收到了这个错误:-

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的内容是

<?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/>

谁能告诉我哪里出错了????

最佳答案

您正在使用 XML 命名空间(在本例中为上下文)而没有声明它

把你的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: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 ,我认为不存在。

关于xml - 找不到元素 'context:annotation-config' 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18802982/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com