Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Spring
Springhard

Spring AOP proxies — what is the self-invocation problem?

Tags
#aop#proxy#transactional
Back to categoryPractice quiz

Answer

Spring AOP usually works via a proxy around your bean. If a method inside the same class calls another advised method directly (`this.someMethod()`), it bypasses the proxy, so aspects like `@Transactional` may not apply.

Advanced answer

Deep dive

Spring AOP is usually **proxy-based**:

  • JDK dynamic proxies when you proxy an interface.
  • CGLIB proxies when you proxy a concrete class (subclassing).

The proxy intercepts calls **made through the proxy**. When code inside the bean calls another method on `this`, it never leaves the target object, so the proxy can’t intercept it.

Example (the issue)

@Service
class BillingService {
  @Transactional
  public void pay() { /* ... */ }

  public void run() {
    this.pay(); // bypasses proxy -> no transaction
  }
}

Fixes

  • Extract the advised method to another bean and call that bean.
  • Inject the proxied interface and call through it (be careful with design).
  • Use AspectJ weaving only if you truly need to advise self-invocations.

Common pitfalls

  • Annotating private methods with `@Transactional` and expecting it to work.
  • Calling “helper” advised methods from inside the same class.
  • Tests that instantiate classes directly (no proxy) and then expecting AOP behavior.

Related questions

Spring
`@Async` methods: how do they work and what are common pitfalls?
#spring#async#executor
Spring
`@Cacheable`: how does Spring caching work and name two common gotchas?
#spring#cache#cacheable
Spring
What is a `BeanPostProcessor` and when would you use it?
#spring#beanpostprocessor#aop
Spring
How does `@Async` work in Spring and what’s a common gotcha?
#async#executor#proxy
Spring
How does `@Transactional` work (rollback + common gotcha)?
#transaction#transactional#rollback
Spring
How does @Transactional work?
#transaction#aop#database