基于Schema配置的AOP

一、切面配置

1 <aop:config proxy-target-class="true">
2         <aop:pointcut id="pointcut" expression="target(NaiveWaiter) and execution(* greetTo(..))"/>
3         <aop:aspect ref="aspect">
4             <aop:before method="before" pointcut-ref="pointcut"/>
5         </aop:aspect>
6     </aop:config>
7 
8     <bean id="waiter" class="NaiveWaiter"/>
9     <bean id="aspect" class="PreGreetingAspect"/>

proxy-target-class 为true时使用CGLib代理 false时使用JDK. 

环绕通知类需要注意

1 import org.aspectj.lang.ProceedingJoinPoint;
2 public class SurGreetingAspect {
3     public Object sur(ProceedingJoinPoint pjd)throws Throwable {
4         System.out.println("----------------");
5         Object obj=pjd.proceed();
6 
7         return obj;
8     }
9 }

 

posted @ 2017-11-05 21:02  wutingjia  阅读(188)  评论(0编辑  收藏  举报