Results 1 to 4 of 4

Thread: Theoretical AOP question

  1. #1
    Join Date
    Jun 2008
    Location
    Jacksonville, Florida
    Posts
    147

    Default Theoretical AOP question

    Let's say I have a bunch of classes that all implement the same interface class. Each one of these classes will have a different implementation of method doSomething().

    I would like to intercept all exceptions from doSomething() from all of my classes that implement MyInterface. Here's the kicker. My impl classes are not instantiated by me and I have no way to force them to be created by spring. Is it possible to still use AOP for my crosscut? If so, how would I do it? What would the config look like? Can I still do it on classes that I don't have source for? I am very green when it comes to AOP and I am trying to understand its limitations.

  2. #2

    Default

    You can manually create an AOP proxy using a ProxyFactory.
    There's a simple example in http://static.springsource.org/sprin...l#aop-proxying

  3. #3

    Default

    of course you can do that.
    I have something similar, I use it to get a full logger, and I donīt have any proxy, I have a pointcut defined, around and after-throwing, that's all.

    just one thing, when you implement your exception method remember to pass as parameter to this method Throwable, because is father of all exceptions, and you will trace all exceptions without problems.

  4. #4
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    I am guessing that you don't have any control over the creation of the objects for the subclasses (if you do, as suggested, you may manually create proxies for them). In such cases, your best bet is to use the AspectJ weaver.

    Take a look at Spring and AspectJ documentation to get started.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

Posting Permissions

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