java 如何调试 Spring AOP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5141853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:39:49  来源:igfitidea点击:

How to debug Spring AOP

javadebuggingspringloggingaop

提问by Jens Schauder

I have a problem with Spring AOP which doesn't ties an aspect to all the methods it should (in my opinion) (see this question for more about the root problem: Spring AOP ignores some methods of Hessian Service).

我对 Spring AOP 有一个问题,它没有将一个方面与它应该的所有方法联系起来(在我看来)(有关根本问题的更多信息,请参阅此问题:Spring AOP 忽略 Hessian Service 的某些方法)。

How can I debug, what methods and instances get combined with what aspect? Is there something like a verbose flag for spring aop, which gives that information?

如何调试,哪些方法和实例与哪些方面结合?是否有类似 spring aop 的详细标志,提供该信息?

采纳答案by Grzegorz Oledzki

There seems not to be too much logging code in the Spring AOP classes, but...

Spring AOP 类中似乎没有太多的日志记录代码,但是......

In case Spring AOP decides to use Cglib to create proxy, there's one line which might help you:

如果 Spring AOP 决定使用 Cglib 创建代理,有一行可能对您有所帮助:

    // in org.springframework.aop.framework.Cglib2AopProxy.getProxy(ClassLoader)
    if (logger.isDebugEnabled()) {
        logger.debug("Creating CGLIB2 proxy: target source is " + this.advised.getTargetSource());
    }

A similar one seems to come in handy when JDK proxies are used:

当使用 JDK 代理时,类似的方法似乎会派上用场:

    // in org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(ClassLoader)
    if (logger.isDebugEnabled()) {
        logger.debug("Creating JDK dynamic proxy: target source is " + this.advised.getTargetSource());
    }

Just try to turn on DEBUG-level logging for these two classes and see what's the output.

只需尝试为这两个类打开调试级别的日志记录,看看输出是什么。