【问题标题】:org.xml.sax.SAXParseException: The matching wildcard is strict, but no declaration can be found for element 'aop:config'org.xml.sax.SAXParseException:匹配的通配符是严格的,但找不到元素“aop:config”的声明
【发布时间】:2016-05-08 11:28:00
【问题描述】:

我是一个新手,我正在研究我的第一个 JAVA Spring 应用程序,主要基于 Craig Wall 编写的 Spring in Action 第 4 版中的示例,但我遇到了这个错误......

错误:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 来自类路径资源 [Knights.xml] 的 XML 文档中的第 20 行无效; 嵌套异常是 org.xml.sax.SAXParseException;行号:20; 列号:14; cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“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>

如果有任何建议,我将不胜感激。 谢谢。

【问题讨论】:

  • 你用的是什么版本的Spring?
  • 你应该检查一下 spring-aop 是否在类路径中。如果您使用 Maven,请执行mvn dependency:tree 以获取您的项目依赖项列表。

标签: spring spring-mvc configuration


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-26
    • 2021-11-02
    • 2017-10-20
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 2015-12-05
    相关资源
    最近更新 更多