/**
-
className:{AroundAspect}
*/
@Component
@Aspect
public class AroundAspect {
//不能共用
@Around(value = "com.atguigu.pointcut.PointCut.pcForService()")
public Object methodAround(ProceedingJoinPoint joinPoint){
// 1.通过JoinPoint对象获取目标方法签名对象
// 方法的签名:一个方法的全部声明信息
Signature signature = joinPoint.getSignature();
System.out.println("signature = " + signature);// 2.通过方法的签名对象获取目标方法的详细信息 String methodName = signature.getName();//方法名 System.out.println("methodName = " + methodName); int modifiers = signature.getModifiers();//权限信息 System.out.println("modifiers = " + modifiers); String declaringTypeName = signature.getDeclaringTypeName(); System.out.println("declaringTypeName = " + declaringTypeName); Class getDeclaringType = signature.getDeclaringType(); System.out.println("getDeclaringType = " + getDeclaringType); // 3.通过JoinPoint对象获取外界调用目标方法时传入的实参列表 Object[] args = joinPoint.getArgs();//参数 // 4.由于数组直接打印看不到具体数据,所以转换为List集合 List<Object> argList = Arrays.asList(args); System.out.println("argList = " + argList); //保证目标方法被执行即可 Object result = null; try { //增强代码 -> before System.out.println("[AOP前置通知] " + methodName + "方法开始了,参数列表:" + argList); result = joinPoint.proceed(args); System.out.println("[AOP返回通知] "+methodName+"方法成功结束了,返回值是:" + result); } catch (Throwable e) { System.out.println("[AOP异常通知] "+methodName+"方法抛异常了,异常类型是:" + e.getClass().getName()); throw new RuntimeException(e); }finally { System.out.println("[AOP最后通知] "+methodName); } return result;
}
}
网友评论