Spring AOP 实现原理
什么是AOP
AOP使用场景
实现AOP的技术
如何使用Spring AOP
Spring AOP代理对象的生成
InvocationHandler是JDK动态代理的核心
public Object invoke(Object proxy,Method method,Object[] args) throwsThrowable {MethodInvocation invocation =null;Object oldProxy =null;boolean setProxyContext =false;TargetSource targetSource =this.advised.targetSource;Class targetClass =null;Object target =null;try{//eqauls()方法,具目标对象未实现此方法if(!this.equalsDefined &&AopUtils.isEqualsMethod(method)){return(equals(args[0])?Boolean.TRUE :Boolean.FALSE);}//hashCode()方法,具目标对象未实现此方法if(!this.hashCodeDefined &&AopUtils.isHashCodeMethod(method)){return newInteger(hashCode());}//Advised接口或者其父接口中定义的方法,直接反射调用,不应用通知if(!this.advised.opaque &&method.getDeclaringClass().isInterface()&&method.getDeclaringClass().isAssignableFrom(Advised.class)){// Service invocations onProxyConfig with the proxy config...returnAopUtils.invokeJoinpointUsingReflection(this.advised,method, args);}Object retVal =null;if(this.advised.exposeProxy){// Make invocation available ifnecessary.oldProxy =AopContext.setCurrentProxy(proxy);setProxyContext =true;}//获得目标对象的类target = targetSource.getTarget();if(target !=null){targetClass = target.getClass();}//获取可以应用到此方法上的Interceptor列表List chain =this.advised.getInterceptorsAndDynamicInterceptionAdvice(method,targetClass);//如果没有可以应用到此方法的通知(Interceptor),此直接反射调用 method.invoke(target, args)if(chain.isEmpty()){retVal =AopUtils.invokeJoinpointUsingReflection(target,method, args);}else{//创建MethodInvocationinvocation = newReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);retVal = invocation.proceed();}// Massage return value if necessary.if(retVal !=null&& retVal == target &&method.getReturnType().isInstance(proxy)&&!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())){// Special case: it returned"this" and the return type of the method// is type-compatible. Notethat we can't help if the target sets// a reference to itself inanother returned object.retVal = proxy;}return retVal;}finally{if(target !=null&&!targetSource.isStatic()){// Must have come fromTargetSource.targetSource.releaseTarget(target);}if(setProxyContext){// Restore old proxy.AopContext.setCurrentProxy(oldProxy);}}}
参考文章
Spring AOP 实现原理的更多相关文章
- 【Spring】Spring AOP实现原理
Spring AOP实现原理 在之前的一文中介绍过Spring AOP的功能使用,但是没有深究AOP的实现原理,今天正好看到几篇好文,于是就自己整理了一下AOP实现的几种方式,同时把代理模式相关知识也 ...
- 何为代理?jdk动态代理与cglib代理、spring Aop代理原理浅析
原创声明:本博客来源为本人原创作品,绝非他处摘取,转摘请联系博主 代理(proxy)的定义:为某对象提供代理服务,拥有操作代理对象的功能,在某些情况下,当客户不想或者不能直接引用另一个对象,而代理对象 ...
- Spring Aop底层原理详解
Spring Aop底层原理详解(来源于csdn:https://blog.csdn.net/baomw)
- spring AOP底层原理实现——jdk动态代理
spring AOP底层原理实现——jdk动态代理
- Spring AOP底层原理
------------------siwuxie095 Spring AOP 底层原理 AOP 即 Aspect Or ...
- jdk动态代理与cglib代理、spring Aop代理原理-代理使用浅析
原创声明:本博客来源为本人原创作品,绝非他处摘取,转摘请联系博主 代理(proxy)的定义:为某对象提供代理服务,拥有操作代理对象的功能,在某些情况下,当客户不想或者不能直接引用另一个对象,而代理对象 ...
- Spring框架系列(9) - Spring AOP实现原理详解之AOP切面的实现
前文,我们分析了Spring IOC的初始化过程和Bean的生命周期等,而Spring AOP也是基于IOC的Bean加载来实现的.本文主要介绍Spring AOP原理解析的切面实现过程(将切面类的所 ...
- Spring框架系列(10) - Spring AOP实现原理详解之AOP代理的创建
上文我们介绍了Spring AOP原理解析的切面实现过程(将切面类的所有切面方法根据使用的注解生成对应Advice,并将Advice连同切入点匹配器和切面类等信息一并封装到Advisor).本文在此基 ...
- Spring框架系列(11) - Spring AOP实现原理详解之Cglib代理实现
我们在前文中已经介绍了SpringAOP的切面实现和创建动态代理的过程,那么动态代理是如何工作的呢?本文主要介绍Cglib动态代理的案例和SpringAOP实现的原理.@pdai Spring框架系列 ...
随机推荐
- session_start保存的客户端cookie的值什么时候改变
//cookie记录的session_id立刻改变了session_start();echo "old:".session_id();session_regenerate_id() ...
- HDU1010 Tempter of the Bone
解题思路:相当经典的一题,回溯,具体细节处理见代码. #include<cstdio> #include<cstring> #include<algorithm> ...
- 【英语】Bingo口语笔记(4) - Pick系列
take your pick. 你挑吧 pick on 找茬
- Arduino命令行编译 树莓派连接Arduino 电脑上编译Arduino代码后 通过树莓派烧写到Arduino上
//本教程针对UNO 1.在file->preferences中找到preferences.txt文件 2:用记事本打开preferences.txt,选择hex文件存放的路径,在最后行加入 b ...
- GET与POST在什么情况下使用
GET与POST 你可能想了解GET和POST之间有什么区别,并想知道什么时候使用它们.从理论上讲,如果请求是幂等的就可以使用GET,所谓幂等是指多个请求返回相同的结果.实际上,相应的服务器方法可能会 ...
- JVM参数汇总
一.java启动参数共分为三类: 其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容:其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足 ...
- mongo 安装
mongo 安装: 1.按照 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 安装 2.安装成功后创建用户 d ...
- LoadRunner学习记录--安装遇到的问题一
安装过程中的出现了此计算机上缺少vc2005_sp1_with_atl_fix_redist 需要到这个目录下lrunner\En\prerequisites\vc2005_sp1_redist\ 手 ...
- 用python3破解wingIDE
值得注意的是,python2的整除/在python3中变成了//,sha方法细化成了sha1和sha256,所以破解文件需要更改加密方式和整除部分的编码方式,经过修改后,这个文件可以完美演算出破解码, ...
- Nginx gzip配置详解
gzip决定是否开启gzip模块param:on|offexample:gzip on; gzip_buffers 设置gzip申请内存的大小,其作用是按块大小的倍数申请内存空间param1:intp ...