如何通过Spring AOP记录私有方法? [英] How can I log private methods via Spring AOP?

查看:1019
本文介绍了如何通过Spring AOP记录私有方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用spring aop性能日志记录私有方法. 下面是我正在使用的配置,下面的配置

I am not able to log the private methods using spring aop performance logging. Below is the configuration I am using below configuration

<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 jar.

I am having cglib jar on my class path.

推荐答案

您必须使用编译时编织,而不是Spring AOP的代理用法.

You have to use compile time weaving instead of the proxy usage for Spring AOP.

来自春季AOP-支持的切入点指示符

由于Spring的AOP框架基于代理的性质,因此,无论是JDK代理(不适用)还是CGLIB代理(在技术上可行但不建议AOP使用),根据定义,都不会截获受保护的方法目的).结果,任何给定的切入点将仅与公共方法匹配!

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!

如果您的拦截需求包括受保护的/私有方法甚至是构造函数,请考虑使用Spring驱动的本机AspectJ编织,而不是Spring的基于代理的AOP框架.这构成了具有不同特性的AOP使用模式的不同,因此请确保在做出决定之前先熟悉编织.

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 AOP记录私有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆