1. 前置通知
public void before(JoinPoint joinPoint) {
String classSimpleName = joinPoint.getTarget().getClass().getSimpleName();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
System.out.println("classSimpleName:" + classSimpleName);
System.out.println("methodName:" + methodName);
System.out.println(Arrays.toString(args));
System.out.println("before method");
}
2. 后置通知
public void after(JoinPoint joinPoint,Object ret){
System.out.println("return object:"+ ret);
System.out.println("after method");
}
3. 最终通知
public void finallyMethod(JoinPoint joinPoint){
System.out.println("invoke anymore");
}
4. 异常通知
public void afterThrowing(JoinPoint joinPoint,Throwable ex){
System.out.println(ex.getMessage());
}
5.最终通知
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("before");
Object ret = joinPoint.proceed();
System.out.println("return value:" + ret);
System.out.println("after");
}