Hi,
Is it possible in spring to introduce an aspect that would intercept calls to a commons-beanutils method?
Hi,
Is it possible in spring to introduce an aspect that would intercept calls to a commons-beanutils method?
As long as you use AspectJ code weaving (which Spring 2.0/2.5 supports) you can.
Bill
Even if I am just referencing a class that resides in the commons-beanutils JAR file? (i don't have access to the source)
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.
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.
Oleg Zhurakousky
Spring Integration team
http://twitter.com/z_oleg
http://blog.springsource.com/author/ozhurakousky/
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.