Proceedingjoinpoint 和JoinPoint的区别:
Proceedingjoinpoint 继承了JoinPoint,proceed()这个是aop代理链执行的方法。并扩充实现了proceed()方法,用于继续执行连接点。JoinPoint仅能获取相关参数,无法执行连接点。JoinPoint的方法
1.java.lang.Object[] getArgs():获取连接点方法运行时的入参列表;
2.Signature getSignature() :获取连接点的方法签名对象;
3.java.lang.Object getTarget() :获取连接点所在的目标对象;
4.java.lang.Object getThis() :获取代理对象本身;

proceed()有重载,有个带参数的方法,可以修改目标方法的的参数

这几天学习这一块我们应该可以很快写出来下面的代码没有难点

package com.wfg.aop2.dao;/*** @author wufagang* @description* @date 2021年04月24日 3:03 下午*/
public interface IndexDao {public void saveUser(String user);
}
package com.wfg.aop2.dao;import org.springframework.stereotype.Service;/*** @author wufagang* @description* @date 2021年04月24日 3:03 下午*/
@Service
public class IndexDaoImpl implements IndexDao {@Overridepublic void saveUser(String user) {System.out.println("save user" + user);}
}
package com.wfg.aop2;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;/*** @author wufagang* @description* @date 2021年04月24日 3:08 下午*/
@Configuration
@ComponentScan("com.wfg.aop2")
@EnableAspectJAutoProxy(proxyTargetClass=false)
public class AppConfig {}
package com.wfg.aop2;import com.wfg.aop2.dao.IndexDao;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;/*** @author wufagang* @description* @date 2021年04月24日 3:06 下午*/
@Aspect
@Component
public class IndexAspect {@Before("this(com.wfg.aop2.dao.IndexDaoImpl)")public void before(){System.out.println("before==============");}@After("target(com.wfg.aop2.dao.IndexDaoImpl)")public void after(){System.out.println("after==============");}@Around("target(com.wfg.aop2.dao.IndexDaoImpl)")public void around(ProceedingJoinPoint joinPoint){System.out.println("around start");Object[] args = joinPoint.getArgs();//修改参数for (int i = 0; i <args.length ; i++) {args[i]=args[i]+" update";}String thisname = joinPoint.getThis().getClass().getName();System.out.println(thisname);String targetName = joinPoint.getTarget().getClass().getName();System.out.println(targetName);Signature signature = joinPoint.getSignature();System.out.println(signature.getName());try {joinPoint.proceed(args);} catch (Throwable throwable) {throwable.printStackTrace();}System.out.println("around end ");}
}
package com.wfg.aop2;import com.wfg.aop2.dao.IndexDao;
import com.wfg.aop2.dao.IndexDaoImpl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;import java.lang.reflect.Proxy;/*** @author wufagang* @description* @date 2021年04月24日 3:09 下午*/public class Test2 {public static void main(String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);IndexDao bean = context.getBean(IndexDao.class);System.out.println("类名称:"+bean.getClass().getName());System.out.println("bean instanceof IndexDao :"+(bean instanceof IndexDao));System.out.println("bean instanceof IndexDaoImpl :"+(bean instanceof IndexDaoImpl));System.out.println("bean instanceof Proxy :"+(bean instanceof Proxy));bean.saveUser("zhangsan");}
}

主要代码:

 @Around("target(com.wfg.aop2.dao.IndexDaoImpl)")public void around(ProceedingJoinPoint joinPoint){System.out.println("around start");Object[] args = joinPoint.getArgs();//修改参数for (int i = 0; i <args.length ; i++) {args[i]=args[i]+" update";}String thisname = joinPoint.getThis().getClass().getName();System.out.println(thisname);String targetName = joinPoint.getTarget().getClass().getName();System.out.println(targetName);Signature signature = joinPoint.getSignature();System.out.println(signature.getName());try {joinPoint.proceed(args);} catch (Throwable throwable) {throwable.printStackTrace();}System.out.println("around end ");}

运行结果:

SpringAop环绕通知和JoinPoint and ProceedingJoinPoint相关推荐

  1. SpringAOP——JoinPoint 和 ProceedingJoinPoint

    AOP 的几个概念 名称 解释 Pointcut 切点,决定处理如权限校验.日志记录等在何处切入业务代码中(即织入切面).切点分为execution方式和annotation方式.前者可以用路径表达式 ...

  2. JoinPoint和ProceedingJoinPoint区别

    本文主要介绍JoinPoint的常用方法 原文链接:JoinPoint和ProceedingJoinPoint有啥不一样? 在以一个实际例子演示如何使用注解实现AOP装配时,为了监控应用程序的性能,我 ...

  3. AspectJ中JoinPoint和ProceedingJoinPoint注解的使用

    概念 Joint Point JointPoint是程序运行过程中可识别的点,这个点可以用来作为AOP切入点.JointPoint对象则包含了和切入相关的很多信息.比如切入点的对象,方法,属性等.我们 ...

  4. Java Thread等待,通知和notifyAll示例

    The Object class in java contains three final methods that allows threads to communicate about the l ...

  5. 个人以非货币性资产评估增值出资计征个人所得税问题简析——兼评国税总局 41 号通知和 20 号公告

    个人以非货币性资产评估增值出资计征个人所得税问题简析--兼评国税总局 41 号通知和 20 号公告  资本市场部 熊川 2015 年 3 月 30 日,财政部.国家税务总局发布<关于个人非货币性 ...

  6. 关于JoinPoint和ProceedingJoinPoint区别

    1.ProceedingJoinPoint只适用于环绕通知,因为只有环绕通知,才能控制目标方法的运行. 2.JoinPoint 适用于其它的四大通知类型,可以用来记录运行的数据. 3. Proceed ...

  7. Joinpoint与Proceedingjoinpoint

    1.Joinpoint: Signature getSignature():获取封装了署名信息的对象,在该对象中可以获取到目标方法名,所属类的Class等信息 Object[] getArgs();获 ...

  8. iOS通知和KVO的区别和用法

    [NSNotification.delegate和KVO的区别] 1.效率肯定是delegate比nsnotification高. 2. delegate方法比notification更加直接,最典型 ...

  9. iphone通知和android,手机App 通知数量太多,让你备感压力吗?教你如何消除令人心烦的信息通知(iPhone、Android)...

    手机APP右上角通常会显示通知数量,那个数字或许对有些人来说是倍感压力的,想要清除他却又无法,能有消除App通知数量标记的方法吗?当然有!小编这篇就是要教大家如何在iPhone.Android手机上消 ...

最新文章

  1. 又一壮举!GPT-3首次完成剧本创作,AI解决创造性问题的能力正迅速提升
  2. 使用Powershell如何导出Exchange对象中的多值属性值
  3. SpringMVC+MyBatis 返回时间格式转换的解决方案
  4. 小学奥数 7828 最大公约数与最小公倍数 python
  5. 计算机基础项目任务教学重构,面向计算思维培养的中职课程项目式重构研究
  6. 虚拟寄存器,虚拟堆栈与真实寄存器,真实堆栈如何对应
  7. 运营商大数据的市场价值有哪些
  8. 【转】selenium之 定位以及切换frame
  9. Chromium引擎控件DotNetBrowser V1.14发布 | 附下载
  10. Thinkphp响应式第三四方聚合支付平台源码
  11. 详解python使用browsermobproxy获取当前网页xhr的get数据方法
  12. 计算机的所有符号,电脑上怎么打各种符号
  13. github rust 项目Travis ci配置
  14. Python简介,第2章–字符串和列表
  15. Docker 启动tomcat报错Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use.
  16. Elasticsearch Ingest Pipeline
  17. Linux内部字段分离符环境变量IFS
  18. Android无线WiFi调试项目adbwifi摆脱数据线拔插烦恼无轻松远程调试
  19. OpenCV python去除图片水印
  20. 基于BLE的IoT智能灯泡的安全漏洞利用

热门文章

  1. 树的直径算法(dfs)
  2. 安卓Fragment使用详解
  3. 初创公司如何搭建开发框架_初创公司必须聘请开发者活跃
  4. 转载--研究者开发程序可分辨讽刺类语言
  5. VS Code -- Live Server
  6. 网上办卡,你关注“合约期”了吗?
  7. html行标签并列显示,excel数据透视表_excel数据透视表怎样不显示汇总
  8. vue项目js文件引入第三方库组件
  9. 微信抢红包的算法架构总结
  10. 升级到什么能换鸿蒙,想换华为手机选择这5部:最低1599,最高8999,都能升级到鸿蒙...