Spring AOP works well on methods that exposed via an interface. Spring AOP provides an option on proxy via target class @EnableAspectJAutoProxy(proxyTargetClass=true)
In this case the target class is the proxy, so I assume all of its methods - public, protected and private.
interface ISample {
public method1();
}
class Sample implements ISample {
@LogMe
public method1() {
...
method2();
}
@LogMe
private method2() {
...
}
}
I have cglib library configured in the class path, the config class has @EnableAspectJAutoProxy(proxyTargetClass=true) and the aspect class has @Aspect and @Component. The aspect class logs all method calls if it is annotated with @LogMe.
Question is with this setting method2() call does not get logged? If the proxy is on the target class, should'nt this work?
method2()hasprivateaccess modifier it can't be overridden and hence can't be proxied; which is what you observe. Moreover themethod2()is invoked inline and not via a spring managed bean which could be intercepted. - Bond - Java Bond