自学内容网 自学内容网

【Spring】AOP中JoinPoint和ProceedingJoinPoint相关方法使用

JoinPoint和ProceedingJoinPoint对象
1.JoinPoint对象封装了SpringAop中切面方法的信息,在切面方法中添加JoinPoint参数,就可以获取到封装了该方法信息的JoinPoint对象
2.ProceedingJoinPoint对象是JoinPoint的子接口,该对象只用在@Around的切面方法中

https://zhuanlan.zhihu.com/p/395735251
SpringBoot AOP中JoinPoint的用法和通知切点表达式

在这里插入图片描述

3.打印输出
getString是测试类的方法名,TestController是类名,一起来看看:

joinPoint.getSignature().toString():String com.fast.web.controller.TestController.getString()
joinPoint.getSignature().toShortString():TestController.getString()
joinPoint.getSignature().toLongString():public java.lang.String com.fast.web.controller.TestController.getString()
joinPoint.getSignature().getName():getString
joinPoint.getSignature().getModifiers():1
joinPoint.getSignature().getDeclaringType():class com.fast.web.controller.TestController
joinPoint.getSignature().getDeclaringTypeName():com.fast.web.controller.TestController
附带说明:
getModifiers()方法返回int类型值表示该字段的修饰符。
其中,该修饰符是java.lang.reflect.Modifier的静态属性。
对应表如下:
PUBLIC: 1
PRIVATE: 2
PROTECTED: 4
STATIC: 8
FINAL: 16
SYNCHRONIZED: 32
VOLATILE: 64
TRANSIENT: 128
NATIVE: 256
INTERFACE: 512
ABSTRACT: 1024
STRICT: 2048

4.getTarget()与getThis()
getTarget() 被代理对象,即连接点所在的目标对象
getThis() 代理对象

被代理对象的类名:com.example.worktest.aop.controller.AopController
代理对象的类名:com.example.worktest.aop.controller.AopController$$EnhancerBySpringCGLIB$$877afd82

5.参考

CSDN文档
https://blog.csdn.net/weixin_38446891/article/details/108981465?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-108981465-blog-103344406.235%5Ev43%5Epc_blog_bottom_relevance_base6&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-108981465-blog-103344406.235%5Ev43%5Epc_blog_bottom_relevance_base6&utm_relevant_index=2

原文地址:https://blog.csdn.net/weixin_42369773/article/details/137799119

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!