Sobes.tech
Senior

When are AOP proxies created in Spring?

sobes.tech AI

Answer from AI

Spring AOP proxies are created during the application context initialization, more specifically — when beans to which aspects are applied are created. When Spring detects that a bean should be wrapped in a proxy to implement aspects (such as for transactions, logging, or security), it creates a proxy object instead of the original bean.

This occurs after the bean is created and configured, but before it is used. Depending on the configuration, Spring can use JDK Dynamic Proxy (if the bean implements an interface) or CGLIB proxy (if there are no interfaces). Thus, proxies are created at the initialization stage to intercept method calls and apply additional behaviors defined by aspects.