Announcement Announcement Module
Collapse
No announcement yet.
how to match to method name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to match to method name

    how to match method name? for example:
    public interface IMyBussessObject {
    public String getSomething();
    [b]public String 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.ProxyFact oryBean">
    <property name="target"><ref local="businessObjectTarget"/>
    </property>
    <property name="interceptorNames">
    <list>
    <value>securityInterceptor</value>
    <value>myAdvice</value>
    </list>
    </property>
    </bean>
    </beans>

  • #2
    You need to define two pointCuts:
    1. pointCut for getSomething
    Code:
      <bean id="SecurityPointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice">
          <ref local="securityInterceptor"/>
        </property>
        <property name="pattern">
          <value>.*get.*</value>
        </property>
      </bean>
    2. pointCut for doOtherThing
    Code:
      <bean id="AdvisorPointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <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
    Code:
      <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

    Comment

    Working...
    X