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

  • Pointcut question

    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.

    Thanks!

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

    Comment


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

      Comment


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

        Code:
        <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
            <property name="pattern">
                <value>.*foo.*</value>
            </property>
        </bean>

        Comment


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

          Comment

          Working...
          X