Proxy Limitations, Self-Invocation, Final Methods, Proxy Chaining and Debugging
Learn Proxy Limitations, Self-Invocation, Final Methods, Proxy Chaining and Debugging (Phase 11 · Spring Proxies (Essential), Spring Core) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Why self-invocation bypasses the proxy • The proxy wraps the target: client → proxy → interceptors → target.method() . Inside the target, this is the raw target , so this.other() calls the other method directly ; no interceptor runs. This is the cause of "@Transactional / @Async / @Cacheable does nothing" bugs. • Solutions ranked: (1) restructure: move the advised method to another bean ; (2) inject the proxy of yourself ( @Autowired @Lazy MyService self ); (3) AopContext.currentProxy() with @EnableAspectJAutoProxy(exposeProxy = true) ; (4) AspectJ weaving ( mode = AdviceMode.ASPECTJ ); (5)...