Announcement Announcement Module
No announcement yet.
AOP on nested method invocations Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP on nested method invocations

    I have a quick question on getting AOP to work on nested method invocations (if this is even possible).

    I have the following example:

        public class MyClass {
            // Regular method
            public void method_A() {
            // Aspected method
            public void method_B() {
        public class Test {
            public static void main(String args[]) {
                  MyClass myClass = new MyClass();
                  // Test B - this works properly
                  // Test A - this does not trigger my aspect
    Only method_B() is aspected. I've verified and when an external class calls it, my aspect gets executed.

    However, the call to method_B() from method_A() is not trigerring my Aspect. I debugged into method_A() and as I suspected the value of this variable is MyClass, as opposed to MyClass$EnhancedByCGLIB...

    Is there a way to achieve what I'm trying to do, or do aspects only get triggered when invoked from outside sources.

    I'm using Spring 2.5 with <aop:aspectj-autoproxy proxy-target-class="true"> flag set.
    Last edited by argo516; Apr 7th, 2008, 02:25 PM.

  • #2
    It depends...

    I suggest you read chapter 6 of the reference guide, especially 6.6 it explains how Spring AOP works.

    Spring uses a proxy based approach, which means only externally called methods are intercepted (as you figured out already).

    If you want something else you will need loadtime or compile time weaving.