1

I have configured Spring AOP for 2 different packages in our application to log exceptions. There are 2 different configurations for each package:

<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>

In a service method call, there are calls to the methods of the classes belonging to each of these packages:

public void method() {

method1(); -> package abc

method2(); -> package xyz

}

Some exception occurs in method2 which invokes logExceptionXYZ method where we are wrapping it in a generic exception, say ExceptionXYZ, and throwing it further.

But some how after this, the logExceptionABC method also gets invoked and throws a generic exception , say ExceptionABC.

I'm not able to understand as why logExceptionABC method is getting invoked?

Please let me know if someone knows about such an issue!

Regards, Rahul

Rahul
  • 637
  • 5
  • 16
  • `aop:aspect id` and `aop:pointcut id` are using same IDs.I doubt that could be the problem. You may want to try with unique IDs. – Madhusudana Reddy Sunnapu Mar 14 '16 at 08:40
  • @MadhusudanaReddySunnapu - I had noticed the same aop:aspect id's and trying changing it but didn't worked. I missed aop:pointcut id which is also same, the issue is resolved after changing it. Thanks for pointing it out!! – Rahul Mar 15 '16 at 00:24

1 Answers1

1

Same id is being assigned to both the aop:aspect tags. Similar is the case with the aop:pointcut tags as well.

Try with assigning unique IDs.