RegexpMethodPointcutAdvisor和NameMatchMethodPointcutAdvisor的区别

Spring AOP中有两个PointcutAdvisor——RegexpMethodPointcutAdvisor和NameMatchMethodPointcutAdvisor,它们都在org.springframework.aop.support包中,都可以过滤要拦截的方法。配置方法也大致相同,其中一个最主要的区别是——

RegexpMethodPointcutAdvisor:需要加上完整的类名和方法名,例如:com.xw.methodname或com.*.methodname或.*methodname。

NameMatchMethodPointcutAdvisor:只需要方法名,不用加类名:*methodname。

配置文件如下:

 1:  <bean id="regexp_pointcut"
 2:      class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
 3:      <property name="advice">
 4:          <ref local="advice" />
 5:      </property>
 6:      <property name="patterns">
 7:          <list>
 8:              <value>com.xw.addAll</value>
 9:              <value>com.xw.set</value>
10:          </list>
11:      </property>
12:  </bean>
13:  <bean id="namematch_pointcut"
14:      class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
15:      <property name="advice">
16:          <ref local="advice" />
17:      </property>
18:      <property name="mappedNames">
19:          <list>
20:              <value>add*</value>    
21:          </list>
22:      </property>
23:  </bean>

你可能感兴趣的:(spring,AOP,bean)