View Full Version : Pointcut question
May 16th, 2005, 10:47 AM
I'm new to Spring AOP and I have a question. The Pointcut interface defines a getClassFilter() method, however, since I've been playing around with AOP in spring I noticed that you always specify a specific target for the Dynamic Proxy to weave your aspect into.
If this is the case, when will you ever use an implementation of the ClassFilter interface when you can declaratively state which Class you want to apply your aspect to within the beans xml file?
It seems that you must always declare a target object and slip a proxy in front of it in order to use AOP (ignoring cg-lib). I just can't see how the ClassFilter even has a chance to work when you specifically choose which class to sprinkle with advice in the configuration file.
Any help on this matter would be greatly appreciated. :)
May 17th, 2005, 05:15 AM
when will you ever use an implementation of the ClassFilter interface when you can declaratively state which Class you want to apply your aspect to within the beans xml file?
It is needed internally (e.g. see AbstractRegexpMethodPointcut) and you can use it for your own pointcuts definitions.
May 17th, 2005, 09:54 AM
I'm not sure I understand your reply. I know that I could use a ClassFilter in my own implementation of a Pointcut, however, what's the point (no pun intended) if the factory's xml file is going to specify a specific class for a target to proxy.
I was doing some reading and although I haven't gotten far enough it seems the autoproxying may explain the use of the ClassFilter since you can have proxies generated automatically and perhaps have them use a "group" of Advisors yet you will want to restrict certain advisors to certain classes. Does that make any sense? I probably have to do more reading -- although I was hoping for a quick answer so I can say, "ahhhhh!". :)
May 17th, 2005, 04:32 PM
what's the point (no pun intended) if the factory's xml file is going to specify a specific class for a target to proxy
You can specify a group of classes and methods. E.g.
<bean class="org.springframework.aop.support.JdkRegexpMethodPoi ntcut">
May 18th, 2005, 06:37 PM
Yes, I think I answered my own question. The ClassFilter really shines when you're autoproxying -- especially when you're autoproxying all your beans you can specify the Advisors of your choice with the Advice/Pointcut pairs where your pointcut would include a ClassFilter because you may not want the autoproxy to target all your beans.
I find it that most people will not use autoproxying as much as you think which makes the ClassFilter much less important than it may seem when reading about it. I still have a long way to go reading about Spring. I think Rod Johnson and his team have done a wonderful job with this framework.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.