Spring / Spring Retry Interview Questions
What is the proxyTargetClass attribute in @EnableRetry?
The proxyTargetClass attribute of @EnableRetry controls whether Spring Retry uses subclass-based CGLIB proxies or interface-based JDK dynamic proxies to intercept methods annotated with @Retryable.
Default behavior:
@EnableRetry // proxyTargetClass = false by default
public class AppConfig { }When proxyTargetClass = false (default), Spring uses JDK dynamic proxies. This requires the bean to implement at least one interface. The @Retryable method must be declared on the interface for the proxy to intercept it.
When proxyTargetClass = true, Spring uses CGLIB to create a subclass proxy of the concrete class, so no interface is needed:
@EnableRetry(proxyTargetClass = true)
public class AppConfig { }When to use proxyTargetClass = true:
- Your service classes do not implement interfaces
- You want retry on methods that are not declared on any interface
- You encounter proxy-related class cast exceptions at runtime
In Spring Boot applications that already use CGLIB for @Configuration classes, setting proxyTargetClass = true is consistent and avoids mixed proxy types. The CGLIB approach has a slight startup cost for proxy generation but no runtime overhead difference.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
