Announcement Announcement Module
Collapse
No announcement yet.
Aop does not work for the method called in the same instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aop does not work for the method called in the same instance

    I tried to use AOP to proxy LoggingInterceptor to all the method in a class.

    Class sampleClass {

    public void methodA(){
    this.methodB();
    }

    public void methodB(){}

    }

    I found that if I call methodA from other class, the proxy for methodB does not work. If I call methodB from other class directly, the proxy works fine.

    I wonder if there's solution that won't use the API of Spring. (I mean the un-intrusive approach).


    thanks

  • #2
    Originally posted by olivezuo View Post
    I found that if I call methodA from other class, the proxy for methodB does not work.
    That's a known limitation of the proxy-based approach, documented well and discussed extensively and repeatedly in this forum.

    Originally posted by olivezuo View Post
    I wonder if there's solution that won't use the API of Spring.
    AspectJ can do this.

    Joerg

    Comment


    • #3
      Originally posted by olivezuo View Post
      I wonder if there's solution that won't use the API of Spring. (I mean the un-intrusive approach).
      thanks
      One (hackyish) solution you have is to introduce a delegate and move methodB into the delegate. If you DI the delegate then you will get the proxy and the AOP advice will work.

      Other than that (and without using Spring's API) then as Jörg Heinicke stated, you might be better off using AspectJ.

      Comment

      Working...
      X