Spring的AOP通知:
包括:前置通知, 环绕通知, 环绕后通知, 正常返回通知, 异常通知, 最终通知
package com.niubai.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
public class MyAspect1 {
public void before() {
System.out.println("前置通知");
}
public void after() {
System.out.println("最终通知");
}
public Object around(ProceedingJoinPoint point) {
Object obj = null;
System.out.println("环绕通知");
Object[] objs = point.getArgs();
System.out.println("被代理的对象:" + point.getTarget());
System.out.println("代理对象自己:" + point.getThis());
for (int i = 0; i < objs.length; i++) {
Object ob = objs[i];
System.out.println(ob);
}
try {
obj = point.proceed();
} catch (Throwable e) {
// TODO: handle exception
e.printStackTrace();
}
System.out.println("环绕后通知");
return obj;
}
public void afterThrowing() {
System.out.println("异常通知...");
}
public void afterReturn() {
System.out.println("正常返回通知...");
}
}