org.xml.sax.SAXParseException:匹配的通配符是严格的,但是没有为元素'aop:config'找到声明

问题描述:

我是一个新手,通过我的第一个JAVA Spring应用程序,主要基于Spring in Action第四版由Craig墙和我卡在这个错误...org.xml.sax.SAXParseException:匹配的通配符是严格的,但是没有为元素'aop:config'找到声明

错误:

 
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 
Line 20 in XML document from class path resource [Knights.xml] is invalid; 
nested exception is org.xml.sax.SAXParseException; lineNumber: 20; 
columnNumber: 14; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:config'. 

我的应用程序的工作,我期望没有XML文件中的<aop:config>标签。

有问题的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://springframework.org/schema/aop" 
xsi:schemaLocation="http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd"> 

    <bean id="knight" class="knights.BraveKnight"> 
     <constructor-arg ref="quest" /> 
    </bean> 
    <bean id="quest" class="quests.SlayDragonQuest"> 
     <constructor-arg value="#(T(System).out)" /> 
    </bean> 
    <bean id="minstrel" class="epic.Minstrel"> 
     <constructor-arg value="#(T(System).out" /> 
    </bean> 

    <aop:config> 
     <aop:aspect ref="minstrel"> 
      <aop:pointcut id="embark" expression="execution(* *.embarkOnQuest(..))" /> 

      <aop:before pointcut-ref="embark" method="singBeforeQuest" /> 

      <aop:after pointcut-ref="embark" method="singAfterQuest" /> 
     </aop:aspect> 
    </aop:config> 
</beans> 

我会很感激的任何建议。 谢谢。

+0

您正在使用的是什么版本的Spring? – Tunaki

+0

如果spring-aop在类路径上,你应该检查。如果您使用Maven,请执行'mvn dependency:tree'来获取您的项目依赖关系列表。 – dunni

尝试在名称空间元素中添加一个www:xmlns:aop="http://www.springframework.org/schema/aop"