Loading

Quipoin Menu

Learn • Practice • Grow

spring / Weaving Example
interview

Q1. What is weaving in AOP?
Weaving is the process of linking aspects with other application types or objects to create an advised object. It can be done at compile time, load time, or runtime. Spring AOP performs runtime weaving by creating proxies.

Q2. What are the different types of weaving?
Compile-time weaving: aspects are woven during compilation using AspectJ compiler. Load-time weaving: aspects are woven when classes are loaded using a weaving agent. Runtime weaving: proxies are created dynamically at runtime (Spring AOP).

Q3. How does Spring AOP achieve weaving?
Spring AOP uses proxy-based weaving at runtime. For interfaces, it uses JDK dynamic proxies. For classes, it uses CGLIB proxies. The proxy is created when the bean is instantiated and wraps the target object, intercepting method calls to apply advice.

Q4. What is load-time weaving (LTW) in Spring?
LTW allows aspects to be woven when classes are loaded into the JVM. Spring can integrate with AspectJ LTW by enabling or @EnableLoadTimeWeaving. This requires a Java agent (spring-instrument) for weaving.

Q5. Can you use AspectJ compile-time weaving with Spring?
Yes, you can use AspectJ compiler to weave aspects at compile time, and then use the woven classes in Spring. This is more efficient but requires build configuration. Spring can still manage the beans.