Results 1 to 3 of 3

Thread: Spring AOP with CGLIB proxies, matching methods on super-types

Threaded View

  1. #1
    Join Date
    Jan 2005
    Posts
    9

    Default Spring AOP with CGLIB proxies, matching methods on super-types

    Hi,

    I've scanned the Spring 2.5.1 and AspectJ docs on this, but I can't find the best solution. It may well be staring me in the face ...

    The question is - when using Spring AOP with CGLIB2 proxies, can I declare a pointcut to match all methods called only on a particular concrete class, including methods that are actually declared in that classes' super-types?

    Example - I have two concrete classes com.mypackage.MySubClass extends com.mypackage.MyBaseClass, and MyBaseClass declares a method methodInBaseClass(). I want a pointcut on execution of any method in MySubClass, including methodInBaseClass(). I do _not_ want the pointcut to match execution of methodInBaseClass() in MyBaseClass or subclasses other than MySubType.

    If I declare:

    Code:
    <aop:pointcut id="anySubClassMethod"
            expression="execution(* com.mypackage.MySubClass.*(..))" />
    ... I don't seem to generate advice on execution of methodInBaseClass() in MySubClass. Switching to matching MyBaseClass will provide advice on MySubClass#methodInBaseClass(), but also generates unwanted matches in the base class and other subtypes.

    I'm guessing that I could achieve this by using @AspectJ notation and combining expressions (any thoughts on the best expression?), but if possible, I'd like to stick with Spring XML AOP configuration.

    I realise that this might be a stretch, and that proxying is normally by interfaces, but - is this possible?

    Thanks,
    Brett
    Last edited by brett_s_r; Feb 5th, 2008 at 03:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •