Spring-AOP通知获取数据
推荐先阅读
:Spring全家桶
获取切入点方法的参数:所有通知
JoinPoint:适用于
@Before
、@After
、@AfterReturning
、@AfterThrowing
// JoinPoint对象描述了连接点方法的运行状态,可以获取到原始方法的调用参数
public void before(JoinPoint jp){
Object[] args = jp.getArgs();
System.out.println(Arrays.toString(args));
}ProceedingJoinPoint:适用于
@Around
// ProceedJointPoint是JoinPoint的子类
public Object around(ProceedingJoinPoint pjp)throws Throwable {
Object[] args = pjp.getArgs();
System.out.println(Arrays.toString(args));
Object ret = pjp.proceed();
return ret;
}
获取切入点方法返回值:@Before
和@AfterThrowing
是没有返回值,@After
可有可无,所以不做研究
@AfterReturning
public void afterReturning(Object ret) {
System.out.println("afterReturning advice ..."+ret);
}@Around
public Object around(ProceedingJoinPoint pjp) throws Throwable{
Object ret = pjp.proceed();
return ret;
}
获取切入点方法运行异常信息:@Before
和@AfterReturning
是不会有,@After
可有可无,所以不做研究
@AfterThrowing
public void afterThrowing(Throwable t){
System.out.println("afterThrowing advice ..." + t);
}@Around
public Object around(ProceedingJointPoint pjp){
Object ret = null;
try {
ret = pjp.proceed();
} catch (Throwable t) {
t.printStackTrace();
}
return ret;
}