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

  • RegExpMethodPointcut examples?

    I've been dipping my toe in the waters of Spring AOP with a simple interceptor which does nothing but log when it is being used, using a method in a Test class called doTest(). When I test it with the following in the config, it works.


    <bean id="methodTestPointCut" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <ref local="testInterceptor"/>
    </property>
    <property name="patterns">
    <list>
    <value>.*</value>
    </list>
    </property>
    </bean>

    However, when I change the pattern to <value>.do*</value> or <value>.do.*</value>, it no longer gets intercepted, which surprises me as the method is called 'doTest()'. So how do I intercept all methods beginning with 'do' or 'get' or whatever? Are there some examples somewhere?

  • #2
    Try do.*

    A dot means "any character" and the asterisk means "zero or more times".
    For a more detailed explanation of regular expression syntax you might have a look at the javadoc for the class java.util.regex.Pattern.

    Regards,
    Andreas

    Comment


    • #3
      Originally posted by Andreas Senft
      Try do.*

      A dot means "any character" and the asterisk means "zero or more times".
      For a more detailed explanation of regular expression syntax you might have a look at the javadoc for the class java.util.regex.Pattern.
      If you mean, 'do.*' as opposed to '.do.*' (mentioned in my original post), this doesn't work either. I just figured it out, though - I wasn't allowing for the class as well as the method in the regexp, so the following works:

      .*\.do.*

      That is, any string, followed by a period, followed by 'do' plus any string.

      Comment


      • #4
        I see. I've not been aware of the necessity to provide the classname also. I thought the method name would be enough. :oops:

        Anyway, good that it works now.

        Regards,
        Andreas

        Comment

        Working...
        X