Advised,Advisor,Advice,Pointcut

Advised->在Spring中建立了AOP代理以後,就可以使用org.springframework.aop.framework.Advised接口對它們進行管理。 任何AOP代理都可以被轉型爲這個接口,不論它實現了哪些其它接口spring

Advisor->相似使用Aspect的@Aspect註解的類代理

Advice->@Before、@After、@AfterReturning、@AfterThrowing、@Around日誌

Pointcut->@Pointcutcode

 

package com.enjoy.cap10.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

//日誌切面類
@Aspect
public class LogAspects {
   @Pointcut("execution(public int com.enjoy.cap10.aop.Calculator.*(..))")
   public void pointCut(){};
   
   //@before表明在目標方法執行前切入, 並指定在哪一個方法前切入
   @Before("pointCut()")
   public void logStart(JoinPoint point){
      System.out.println("除法運行....參數列表是:{}");
   }
   @After("pointCut()")
   public void logEnd(){
      System.out.println("除法結束......");
      
   }
   @AfterReturning("pointCut()")
   public void logReturn(){
      System.out.println("除法正常返回......運行結果是:{}");
   }
   @AfterThrowing("pointCut()")
   public void logException(){
      System.out.println("運行異常......異常信息是:{}");
   }
   
   @Around("pointCut()")
   public Object Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
      System.out.println("@Arount:執行目標方法以前...");
      Object obj = proceedingJoinPoint.proceed();//至關於開始調div地
      System.out.println("@Arount:執行目標方法以後...");
      return obj;
   }
}
相關文章
相關標籤/搜索