如何解决调用内部方法切面不起作用的问题?

110 阅读1分钟

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

首先,在切面类中设置:@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
@Aspect
@Component
@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
public class AspectConfig {}


然后,调用哪个内部方法就使用:AopContext.currentProxy() // 意思是通过代理对象调用这个方法,而不是this对象。
((RealType) AopContext.currentProxy()).push(a, b, c);