加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 为什么Spring AOP不拦截受保护的方法

发布时间:2020-12-15 01:27:28 所属栏目:大数据 来源:网络整理
导读:我熟悉Spring AOP.正如我在春季文档http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/aop.html中所读到的,Spring AOP致力于代理的概念. 在8.2.3.1支持的切入点指示符部分中,我找到了以下注释 Due to the proxy-based nature of Spr

我熟悉Spring AOP.正如我在春季文档http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/aop.html中所读到的,Spring AOP致力于代理的概念.

在8.2.3.1支持的切入点指示符部分中,我找到了以下注释

Due to the proxy-based nature of Spring’s AOP framework,protected
methods are by definition not intercepted,neither for JDK proxies
(where this isn’t applicable) nor for CGLIB proxies (where this is
technically possible but not recommendable for AOP purposes). As a
consequence,any given pointcut will be matched against public methods
only!

起初,我不相信它,所以我试图在不使用接口的情况下实现它,默认情况下所有方法都是公开的,并且对上述情况感到惊讶.由于代理类是建议/目标对象的子类,受保护的方法可以由子类访问,所以我认为受保护的方法可以正常工作.

有人可以告诉我为什么不拦截受保护的方法?我错过了什么吗?

最佳答案
JDK代理基于接口,这意味着所有实现的方法都是公共的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读