PDA

View Full Version : RegExpMethodPointcut examples?



jonmor
Feb 7th, 2005, 05:37 AM
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.RegexpMethodPointc utAdvisor">
<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?

Andreas Senft
Feb 7th, 2005, 06:08 AM
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

jonmor
Feb 7th, 2005, 06:32 AM
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.

Andreas Senft
Feb 7th, 2005, 07:25 AM
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