Results 1 to 10 of 18

Thread: newbie: AOP question

Hybrid View

  1. #1

    Default newbie: AOP question

    Hi,
    Is it possible in spring to introduce an aspect that would intercept calls to a commons-beanutils method?

  2. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    As long as you use AspectJ code weaving (which Spring 2.0/2.5 supports) you can.
    Bill

  3. #3

    Default

    Even if I am just referencing a class that resides in the commons-beanutils JAR file? (i don't have access to the source)

  4. #4
    Join Date
    Aug 2006
    Posts
    236

    Default

    I pretty sure you need to use AspectJ to do the weaving of jar files. I'm not 100% sure you can do it in spring, cos spring won't have control of the jar...someone can correct me if i'm wrong.

  5. #5
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    Quote Originally Posted by borfnorton View Post
    Even if I am just referencing a class that resides in the commons-beanutils JAR file? (i don't have access to the source)
    Yes. Source access isn't necessary. AspectJ byte code weaving is very slick. And once you understand how it works, is very powerful. Check out the Spring reference manual for more detail.
    Bill

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Just wanted to add few more clarification points:

    SpringAOP is Proxy based AOP. In other words it's Spring implementation of Java Dynamic Proxy API. With CGLIB Proxies it became even more flexible by allowing you to intercept methods on the classes that do not implement any interfaces. But with all the benefits of elegant OO approach to AOP paradigm it also has some limitations. One of them is limitations on the pointcuts supported by the Spring AOP. Keep in mind Spring AOP was never in the business of competing with byte-code-injection style of AOP represented by AspectJ and JBossAOP.

    Now, back to your question. Could you use Spring AOP on the class to which you have no source code? The answer is yes, regardless of which AOP technique (byte code injection or dynamic proxies) you are using. The only limitations would be standard JDK packages (you can not weave/inject anything into them), but you can write "call" pointcuts to intercept calls to them.

    So unless you have more specific question about what exactly you are trying to do, the answer is within Spring Application Context you can use Spring AOP or AspectJ to intercept calls to commons-beanutils methods.

  7. #7

    Default exactly what I am trying to do

    Hi,
    Thanks for the replies.

    Basically we use struts 1.x and struts uses Apache commons beanutils internally for getting/setting properties on Forms. All of the get/sets go through a class in Apache beanutils called PropertyUtilsBean. This class is in the Apache Commons beanutils JAR.

    We would like to intercept calls to PropertyUtilsBean.getProperty(bean, propName) and before it is called:

    a) if the bean is an "instanceof" a particular class, call a method on on of our classes instead of entering the getProperty() method

    b) if the bean is NOT an "instanceof" this particular class, simply continue execution of the getProperty() method.

Posting Permissions

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