Spring 提供了四種AOP支撐:
基于代理的經(jīng)典spring aop;
純POJO切面
@AspectJ注解驅(qū)動(dòng)的切面
注入式AspectJ切面
前三種都是Spring AOP的變體。
下圖是一個(gè)切點(diǎn)表達(dá)式秘症,代表perform方法執(zhí)行時(shí)觸發(fā)通知的調(diào)用
image.png
進(jìn)入主題犬耻,spring實(shí)戰(zhàn)學(xué)習(xí)佩耳,如何切面,粗讀了一遍她按,敲了一些代碼,比較容易理解比勉,但是沒(méi)測(cè)試看不到結(jié)果感覺(jué)很虛清钥,這一章暫時(shí)放著,悶頭跟著書(shū)實(shí)現(xiàn)一個(gè)web應(yīng)用程序后众,再回頭閱讀效果可能更好胀糜。
package concert;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class Audience {
@Pointcut("execution(** concert.Performance.perform(..))")
public void performance() {}
@Before("performance()")
public void silenceCellPhones(){
System.out.println("Silenceing cell phones");
}
@Before("performance()")
public void takeSeats(){
System.out.println("take a seats");
}
@AfterReturning("performance()")
public void applause(){
System.out.println("拍手 clap");
}
@AfterThrowing("performance()")
public void demandRefund(){
System.out.println("demanding a refund");
}
}