1

我在我们的应用程序中为 2 个不同的包配置了 Spring AOP 来记录异常。每个包有 2 种不同的配置:

<aop:config>
    <aop:aspect id="aspectLoggging" ref="abcExceptionAspect">
        <aop:pointcut id="pointCut"
            expression="execution(* com.abc.*.*(..))" />
        <aop:before method="logBefore" pointcut-ref="pointCut" />
        <aop:after-throwing method="logExceptionABC"
            throwing="error" pointcut-ref="pointCut" />
        <aop:after method="logAfter" pointcut-ref="pointCut" />
    </aop:aspect>
</aop:config>

<aop:config>
    <aop:aspect id="aspectLoggging" ref="xyzlogAspect">
        <aop:pointcut id="pointCut"
            expression="execution(* com.xyz.*.*(..))" />
        <aop:before method="logBefore" pointcut-ref="pointCut" />
        <aop:after method="logAfter" pointcut-ref="pointCut" />
        <aop:after-throwing method="logExceptionXYZ"
            throwing="error" pointcut-ref="pointCut" />
    </aop:aspect>
</aop:config>

在服务方法调用中,会调用属于这些包中的每一个的类的方法:

公共无效方法(){

方法1();-> 包 abc

方法2();-> 包 xyz

}

在调用 logExceptionXYZ 方法的方法 2 中发生了一些异常,我们将它包装在一个通用异常中,比如 ExceptionXYZ,并进一步抛出它。

但是在这之后,logExceptionABC 方法也会被调用并抛出一个通用异常,比如 ExceptionABC。

我无法理解为什么调用 logExceptionABC 方法?

如果有人知道这样的问题,请告诉我!

问候, 拉胡尔

4

1 回答 1

1

同样id被分配给两个aop:aspect标签。aop:pointcut标签的情况也类似。

尝试分配唯一的 ID。

于 2016-03-15T01:17:38.180 回答