PDA

View Full Version : apply JdkRegexpMethodPointcut to multiple beans? how?



pjydc
Apr 7th, 2005, 11:19 PM
Hi, I want to apply an advisor to multiple beans at the same time. I tried BeanNameAutoProxyCreator as follows:

<bean id="myAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNa meAutoProxyCreator">
<property name="beanNames">
<value>*Manager</value>
</property>
<property name="interceptorNames">
<list>
<idref bean="myAdvisor"/>
</list>
</property>
</bean>

<bean id="advisor" class="org.springframework.aop.support.DefaultPointcutAdv isor">
<property name="advice">
<ref local="myInterceptor"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.support.JdkRegexpMethodPoi ntcut">
<property name="pattern">
<value>^org.example.service.[a-zA-Z]{1}(\\w)*Manager.(\\w)*</value>
</property>
</bean>
</property>
</bean>

The reason why I am using JdkRegexpMethodPointcut is because there are many other Manager objects that are from the Spring and other packages. So I want to add some restriction.

The problem is that none of my service methods get called. Am I doing something wrong? Is the above declaration correct?

Thanks, Pete

katentim
Apr 9th, 2005, 01:31 AM
Don't you get a NoSuchBeanDefinitionException?
Shouldn't <idref bean="myAdvisor"/> be <idref bean="advisor"/>?

pjydc
Apr 9th, 2005, 04:14 PM
you are right. it should be <idref bean=advisor"/> and it is in my
application. it is a typo here only.

i did not get any exception.

thanks, pete

katentim
Apr 9th, 2005, 05:54 PM
Your cofiguration looks right - try testing with a simpler regular expression.

omarps
Jul 22nd, 2008, 05:20 PM
I made this one to look for DAO methods:

<bean id="daoPointcut"
class="org.springframework.aop.support.JdkRegexpMethodPoi ntcut">
<property name="pattern"
value="^[a-zA-Z0-9.]+Dao.[a-zA-Z0-9() ]+$" />
</bean>

Just change the "Dao" for Manager, Service, Controller, etc.

Regards,
Omar