spring_aop注解

前置通知注解

@Component("before")    //声明是spring容器的bean组件
@Aspect                         //声明当前组件是切面组件
public class Before{
      //表示doBefore函数是一个前置通知 + 该前置通知的切入点程序
      @org.aspectj.lang.annotation.Before("execution(* com..*.*(..)")
         public void doBefore(JoinPoint jp){
    }  
}

后置通知注解

@Component
@Aspect
public class After{
  @AfterReturning(pointcut="execution(* com..*.*(..))",returning="ret")
public void doAfter(JoinPoint pjp,Object ret){
  System.out,print("目标程序与aop程序执行后将最后执行,返回参数为:" + ret);  
}  
}

异常通知注解

@Component
@Aspect
public class ThrowException{
    @AfterThrowing(pointcut = "execution(* com..*.*(..) )",throwing="e")
    public void doThrow(JoinPoint jp,Throwable e){
}
}

最终通知注解方法

@Component
@Aspect
public class AfterFinally{
  @After(value="execution(* com..*.*(..))")  
  public void afterFinally(JoinPoint jp){
    }
}

环绕通知注解方法

@Component
@Aspect
public class Around{
@org.aspectj.lang.annotation.Around("execution(* com..*.*(..))")
   public String around(ProceedingJoinPoint pjp){
    }
}

猜你喜欢

转载自www.cnblogs.com/fionalde/p/9119984.html