JDK代理中
会代理对象中的所有方法,对于Object中继承的方法,会代理toString方法,但是不会代理equals,hashCode,getClass方法。
原因在于在Spring中的JdkDynamicAopProxy类中的invoke方法执行时会判断
if ((!this.equalsDefined) && (AopUtils.isEqualsMethod(method))) { return Boolean.valueOf(equals(args[0])); } if ((!this.hashCodeDefined) && (AopUtils.isHashCodeMethod(method))) { return Integer.valueOf(hashCode()); } if ((!this.advised.opaque) && (method.getDeclaringClass().isInterface()) && (method .getDeclaringClass().isAssignableFrom(Advised.class))) { return AopUtils.invokeJoinpointUsingReflection(this.advised, method, args); }
所以在调用这三个方法时并不会被代理。
CGLIB代理
与JDK类似,都会进行方法判断,但是该代理的运行方式还不理解,判断方法在本类中并没有使用。应该是在别的类中调用,并根据返回值判断是否代理
if (AopUtils.isFinalizeMethod(method)) { CglibAopProxy.logger.debug("Found finalize() method - using NO_OVERRIDE"); return 2; } if ((!this.advised.isOpaque()) && (method.getDeclaringClass().isInterface()) && (method .getDeclaringClass().isAssignableFrom(Advised.class))) { if (CglibAopProxy.logger.isDebugEnabled()) { CglibAopProxy.logger.debug("Method is declared on Advised interface: " + method); } return 4; } if (AopUtils.isEqualsMethod(method)) { CglibAopProxy.logger.debug("Found 'equals' method: " + method); return 5; } if (AopUtils.isHashCodeMethod(method)) { CglibAopProxy.logger.debug("Found 'hashCode' method: " + method); return 6;
还有很多不理解,以后如果有更深理解,会更新的
热门文章
- 宠物领养市场经济可行性分析 宠物领养市场经济可行性分析报告
- 2月23日 - 最高速度20M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐
- 动物疫苗的类型包括(动物疫苗的种类和制备原理)
- 兽医站给猫打疫苗多少钱(宠物猫医院打疫苗多少钱一针)
- 在动物医院上班怎么样(动物医院职位)
- HCNP Routing&Switching之Super VLAN_在线工具
- 1月25日 - 最高速度20.7M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐
- 3月13日 - 最高速度23M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐
- 用gcc查看c源文件的汇编代码 C++性能优化技术导论
- 3月16日 - 最高速度22.7M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐