Spring AOP not working for method call inside another method

The aspect is applied to a proxy surrounding the bean. Note that everytime you get a reference to a bean, it’s not actually the class referenced in your config, but a synthetic class implementing the relevant interfaces, delegating to the actual class and adding functionality, such as your AOP.

In your above example you’re calling directly on the class, whereas if that class instance is injected into another as a Spring bean, it’s injected as its proxy, and hence method calls will be invoked on the proxy (and the aspects will be triggered)

If you want to achieve the above, you could split method1/method2 into separate beans, or use a non-spring-orientated AOP framework.

The Spring doc (section “Understanding AOP Proxies”) details this, and a couple of workarounds (including my first suggestion above)

Leave a Comment