【问题标题】:Spring AOP The matching wildcard is strict, but no declaration can be found for element 'aop:config'Spring AOP 匹配通配符严格,但找不到元素'aop:config'的声明
【发布时间】:2022-02-04 22:16:22
【问题描述】:

来自类路径资源 [ApplicationContextAOP.xml] 的 XML 文档中的第 13 行无效;嵌套异常是 org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 匹配通配符是严格的,但是找不到元素 'aop:config' 的声明。 p>

<?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://www.springframework.org/schema/aop"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="audience" class="com.idol.Audience" />

<aop:config>
<aop:aspect ref="audience">

    <!-- Before performance -->     

    <aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))"
    method="takeSeats"/>

    <aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))"
    method="turnOffCellPhones" />

    <!-- After performance -->  

    <aop:after-returning pointcut="execution(*com.idol.performers.Performer.perform(..))"
    method="applaud" />

    <!-- After bad performance(exception thrown) -->    

    <aop:after-throwing pointcut="execution(*com.idol.performers.Performer.perform(..))"
    method="demandRefund" />

</aop:aspect>
</aop:config>
<bean id="poeticDuke" class="com.idol.performers.PoeticJuggler">
<constructor-arg value = "15" />
<constructor-arg ref = "sonnet29" />
</bean>

</beans>

我见过类似的错误,我很确定我的类路径有 org.springframework.aop-3.1.0.M2.jar

你能告诉我我错过了什么吗?

【问题讨论】:

  • 非常感谢您的提问。我遇到了同样的问题,但就我而言,问题是我在类路径中缺少spring-aop.jar;这就是我所缺少的。感谢您引起我的注意。

标签: spring aop


【解决方案1】:

您需要添加到您的架构位置:

xsi:schemaLocation="
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
...
"

【讨论】:

  • 现在我得到了这个 :-( 线程“main” org.springframework.beans.factory.BeanDefinitionStoreException 中的异常:从类路径资源 [ApplicationContextAOP.xml] 解析 XML 文档时出现意外异常;嵌套异常是java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
  • 你错过了aopalliance jar
  • @Aubergine:您应该接受这个答案作为正确答案并提出一个新问题。
  • 这样做了,抱歉,设置它需要很长时间 - 失去耐心。
【解决方案2】:
为之前提供的答案增加了一种可能性: 错误版本的 schemaLocation: http://www.springframework.org/schema/aop/ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 正确版本: http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 原因:“schema/aop”之后的额外“/”

【讨论】:

    【解决方案3】:

    我们收到了元素tx:advice 的类似错误消息,并通过将org.springframework.*-3.0.0.M3.jars 替换为org.springframework.*-3.1.2.RELEASE.jars 来解决它,其中* 表示jar 模块。因此,请尝试获取稳定版本来解决类似问题。

    【讨论】:

      【解决方案4】:

      以下架构定义文件发生在我身上。原因是spring-aop-3.0.xsd 之后的额外 >。删除后解决。

      <?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"
             xmlns:aop="http://www.springframework.org/schema/aop"
             xmlns:jdbc="http://www.springframework.org/schema/jdbc"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                                  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd>
                                  http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
      
      <!--    reference to tht jdbc name space and schema definition file-->
      
          <!--    to enable AspectJ support-->
          <aop:aspectj-autoproxy/>
          
       </beans>
          

      【讨论】:

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