Spring AOP使用限制

本文探讨了Spring AOP框架的特点,特别是基于代理的AOP仅能拦截public方法的问题。若需拦截protected/private方法,则建议采用Spring支持的AspectJ编织技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于代理的AOP只会作用于public的方法。

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!


If your interception needs include protected/private methods or even constructors, consider the use of Spring-driven native AspectJ weaving instead of Spring’s proxy-based AOP framework. This constitutes a different mode of AOP usage with different characteristics, so be sure to make yourself familiar with weaving first before making a decision.


如果要作用于非public方法需要使用Load-time Weaving技术,这种技术不是JavaEE标准,所以需要针对特定环境配置,不利于扩展和维护。


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值