版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jaune161/article/details/51476058
返回通知
在前置通知、后置通知以及环绕通知后。
@AfterReturning(value = "execution(* com..*.sleep(..))" )
public void retAdvice(){
System.out.println("Rt");
}
也可以使用returning
指定返回值的参数名,然后通过传入参数在通知中使用参数。
@AfterReturning(value = "execution(* com..*.getName(..))", returning="name" )
public void retAdvice(String name){
System.out.println(name);
}
异常通知
在方法抛出异常时运行。
使用throwing指定异常作为参数传入时的参数名。在方法中可以通过接收到的参数对异常做记录。
@AfterThrowing(value = "execution(* com..*.sleep(..))", throwing="ex" )
public void throwAdvice(Exception ex){
System.out.println(ex.getMessage());
}