匹配的通配符是严格的,但是没有找到元素' context:annotation-config'

时间:2015-12-23 13:43:38

标签: java xml spring xsd

我的代码: 我已正确配置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 个答案:

答案 0 :(得分:0)

指定xmlns:context="http://www.springframework.org/schema/context"命名空间的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>