gpt4 book ai didi

spring - 如何通过 Spring AOP 记录私有(private)方法?

转载 作者:行者123 更新时间:2023-12-04 21:57:25 25 4
gpt4 key购买 nike

我无法使用 spring aop 性能日志记录私有(private)方法。
下面是我在下面的配置中使用的配置

<aop:config proxy-target-class="true">
<aop:pointcut id="allServiceMethods" expression="execution(* com.mycom.app.abc..*.*(..))"/>
<aop:advisor pointcut-ref="allServiceMethods" advice-ref="performanceMonitor" order="2"/>
</aop:config>

我有 cglib我的类(class)路径上的 jar。

最佳答案

您必须使用编译时编织而不是 Spring AOP 的代理使用。
来自 Spring AOP - Supported Pointcut Designators

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.

关于spring - 如何通过 Spring AOP 记录私有(private)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35299844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com