Announcement Announcement Module
No announcement yet.
Theoretical AOP question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    You can manually create an AOP proxy using a ProxyFactory.
    There's a simple example in


    • #3
      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
        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.