通配符匹配是严格的,但找不到元素“context:annotation-config”的声明。

3

我的代码: 我已经正确配置了XML,添加了所有模式,但仍然出现错误。

Config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       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-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/spring-context-3.2.xsd"
       xmlns:context="http://www.springframework.org/schema/context">
  <context:annotation-config />
  <context:component-scan base-package="com"/>
    <bean id="bean1" class="com.pojos.BookInfo">
    </bean>
</beans>
1个回答

4
你在指定 xmlns:context="http://www.springframework.org/schema/context" 命名空间的 XSD 的位置时有错误:
请将以下部分替换为正确的 XSD 位置:
http://www.springframework.org/schema/spring-context-3.2.xsd

使用

http://www.springframework.org/schema/context/spring-context-3.2.xsd

总之:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       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-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd"
       xmlns:context="http://www.springframework.org/schema/context">
  <context:annotation-config />
  <context:component-scan base-package="com"/>
  <bean id="bean1" class="com.pojos.BookInfo">
  </bean>
</beans>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接