Announcement Announcement Module
Collapse
No announcement yet.
Some aspects not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some aspects not working

    Hey there,


    I've ran into a weird problem that I've narrowed down to:
    - If the execution() pointcut contains a method and that method takes no parameters, the aspect works;
    - If the execution() pointcut contains a method and that method takes 1 or more paramenters, the aspect doesn't work.

    To make things clear, I have this class (SessionManager) that implements ISessionManager interface that has standard getters and setters (getters return something and take no parameters, setters return void and take 1 parameter):

    This works...
    Code:
    <aop:aspect id="aspectOne" ref="echoClient">
      <aop:pointcut id="pcOne" expression="execution(* *..ISessionManager.get*(..))" />
      <aop:before method="printHello" pointcut-ref="pcOne" />
    </aop:aspect>
    This doesn't work...
    Code:
    <aop:aspect id="aspectTwo" ref="echoClient">
      <aop:pointcut id="pcTwo" expression="execution(* *..ISessionManager.set*(..))" />
      <aop:before method="printHello" pointcut-ref="pcTwo" />
    </aop:aspect>
    I've tried it in some other methods and the behaviour is exactly the same: if the method takes arguments, the aspect fails; if the method has no arguments, then the aspect works like a charm.

    I'm sure I must be doing something wrong here, but since I'm kinda new to AOP and Spring, can anyone give me a hint?


    Cheers,
    Bruno


    PS: ISessionManager was an interface extracted from SessionManager class, so I'm sure I'm not missing any methods on the interface.

    PS2: My IDE (IntelliJ Idea) can figure out correctly what methods are to be advised in both cases but when I run the app, only the first aspect works :|
    Last edited by ovokinder; Feb 20th, 2009, 06:12 AM. Reason: Found out what I was doing wrong

  • #2
    Confirmed this by applying an execution pointcut that would target all methods within the class and still, only the ones who take no parameters are being advised.

    You can see that the expression is targeting all methods within the class, 'cause the IDE detects it right.



    But when I run the application, only the ones who take no parameters are being advised. This isn't normal behaviour, is it?

    I'm using spring framework 2.5.6, under Linux.

    Comment


    • #3
      By reading chapter 6.6.1. Understanding AOP proxies I noticed what I was doing wrong:

      The problem I pointed out previously was only happening because I wasn't testing any externally called method with arguments (coincidence, huh?). So I moved the interception point to another zone in the code where it (frankly) makes more sense, thus allowing me to keep using self invocation (this.doSomething()) on that SessionManager.

      Funny thing is that when the setters of that class are used by Spring, they aren't intercepted. I mean, if I call a setter from any of my classes in the code, they are intercepted, when Spring sets the bean's properties, they aren't. But then again, this makes sense because Spring creates an instance of a class and executes the setSomething() on that instance, not on the proxy it later exposes to the other beans.

      Typical case of RTFM

      Comment

      Working...
      X