How to debug Spring AOP

2019-03-18 10:24发布

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

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?

1条回答
放荡不羁爱自由
2楼-- · 2019-03-18 10:33

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

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

    // 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:

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

查看更多
登录 后发表回答