Announcement Announcement Module
Collapse
No announcement yet.
"1" pointcut to "N" method executions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "1" pointcut to "N" method executions

    I made an aspect to my application but I'm thinking that this isn't the best way to do that.
    --> The target is the IMPLEMENTATION class.

    Code:
    	<aop:config>
    		<aop:pointcut id="uniqueConstraintLogicalCheckInterceptorPointcut"
    			expression="execution(public * service.impl.*.update(..)) or execution(public void service.impl.*.save(..))" />
    		<aop:advisor pointcut-ref="uniqueConstraintLogicalCheckInterceptorPointcut"
    			advice-ref="uniqueConstraintLogicalCheckInterceptor" />
    		<!-- "uniqueConstraintLogicalCheckInterceptor" is a bean that implements MethodInterceptor ->
    	</aop:config>

    In few lines, the Aspect is working well and I tested it with the 2 methods, without them and with one or another, but I think that something is going wrong.

    I put a "System.out.println("Specialized method not found, proceeding to the super() method.")" (debug only), because sometimes the methodInvocation.getMethod() throwed NoSuchMethodException and I think that it was because the child class hasn't an implementation (but the super class always has a generic implementation).

    What happen is that the message of the SYSOUT just appears when there's no SAVE method, not for the UPDATE method... And I repeat, even this way, the aspect is being executed.

    What's going wrong? Why the SYSOUT appears just in the SAVE and not in the UPDATE??

    Help, please! I want to understand why.


    ==> Additional information:

    - I figured out that the child class implements a super abstract class B that implements an abstract class A (in other words, Target extends B that extends A);
    - For some reason, the method that is not intercepted if has no child implementation (the UPDATE method, in this case) just has implementation in the super "A" class (the "most" super). Otherwise, the SAVE method is implemented 2 times: in the classes A and B (I don't know why because they aren't mine).

    The problem is solved. For education reasons, I'll put an image here that describes the problem.
    Attachment
    Attached Files
    Last edited by michelrisucci; Jun 18th, 2012, 07:38 AM. Reason: Additional information.

  • #2
    I forced a re-implementation in the super class B (like the SAVE method is re-implemented) and it works perfect, then I can only think that the problem is between the AOP and our Architecture, am I wrong?

    Comment


    • #3
      When matching method-execution join points, if the execution pointcut method signature specifies a declaring type, the pointcut will only match methods declared in that type, or methods that override methods declared in or inherited by that type
      see http://www.eclipse.org/aspectj/doc/r...pointcuts.html

      cheers

      Comment


      • #4
        Hey, chelu. Thank you!

        You came exactly to the point (of the topic, sure...).
        Sometimes we forget that all these things are written IN JAVA and there's no magic.

        The point is that the Aspect WRAPS the class.
        This WRAPPING is the key of the problem and the solution, because it includes to say that you MUST HAVE super implementations.
        Coincides with the fact that you may decide between JDK Interface-based proxies and CGLib Class-based proxies.

        Perfect! Thank you.
        Last edited by michelrisucci; Jun 18th, 2012, 07:15 AM.

        Comment

        Working...
        X