Spring AOP初步学习

SPRING AOP中切点的声明

  1. 使用@Pointcut注解 来实现简便切点表达式的书写
    问题:使用时应为兼容问题导致该注解失效报错 查阅资料后是应为jdk版本与aspectJ jar包版本兼容性问题,jdk.1.6 最好与aspectJ的1.6对应。比如jdk1.7就不行

@Aspect/*该注解表明该类是一个切面*/
public class Audience {

    @Pointcut("execution(* concert.Performance.perform(..))")
    public void easyPoint(){}


    @Before("easyPoint()")
    public void easyChase(){
        System.out.println("go go  go  go");

    }

    @Before("easyPoint()")//定义命名的切点
    public void silenceCellPhones() {
        System.out.println("silencing  my cell phones");
    }

    @Before("execution(* concert.Performance.perform(..))")
    public void takeSeats() {
        System.out.println("i have take my seats");
    }

    @AfterReturning("easyPoint()")
    public void applause() {
        System.out.println("clap clap clap");
    }

    @AfterThrowing("easyPoint()")
    public void demandRefund() {
        System.out.println("demand a refund");
    }
}

你可能感兴趣的:(Spring实战)