PDA

View Full Version : how to match to method name


pinglu
Aug 16th, 2004, 01:18 PM
how to match method name? for example:
public interface IMyBussessObject {
public String getSomething();
public String [b] doOtherthing();
}

I only want to do scuritycheck on getSomething, and do advice doOtherthing();
here is my application.xml:which will apply to all the method

<beans>
<bean id="myAdvice" class="com.ping.springdemo.MyAdvice">
</bean>
<bean id="businessObjectTarget" class="com.ping.MyBusinessObject" />
<bean id="securityInterceptor" class="com.ping.springdemo.SecurityInterceptor" />
<bean id="businessObject"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="businessObjectTarget"/>
</property>
<property name="interceptorNames">
<list>
<value>securityInterceptor</value>
<value>myAdvice</value> </list>
</property>
</bean>
</beans>

irbouho
Aug 16th, 2004, 02:49 PM
You need to define two pointCuts:
1. pointCut for getSomething

<bean id="SecurityPointCut" class="org.springframework.aop.support.RegexpMethodPointc utAdvisor">
<property name="advice">
<ref local="securityInterceptor"/>
</property>
<property name="pattern">
<value>.*get.*</value>
</property>
</bean>

2. pointCut for doOtherThing

<bean id="AdvisorPointCut" class="org.springframework.aop.support.RegexpMethodPointc utAdvisor">
<property name="advice">
<ref local="myAdvice"/>
</property>
<property name="pattern">
<value>.*do.*</value>
</property>
</bean>

then you have to apply these pointCuts to your businessObject

<bean id="businessObject" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="businessObjectTarget"/>
</property>
<property name="interceptorNames">
<list>
<value>SecurityPointCut</value>
<value>AdvisorPointCut</value>
</list>
</property>
</bean>


HTH