Java / Micronaut Interview questions
Explain the internal working of Micronaut's AOP proxy generation?
Micronaut generates AOP proxies as ordinary subclasses at compile time, rather than the runtime bytecode generation used by CGLIB or JDK dynamic proxies.
When a method carries a meta-annotation built with @Around, like the built-in @Retryable or a custom one, the processor generates a subclass of the bean that overrides that method. The generated override doesn't contain your business logic directly; instead it constructs a MethodInvocationContext and hands it to the resolved chain of MethodInterceptor beans that apply to that annotation, in the order they're registered.
Each interceptor decides whether to call context.proceed() to continue the chain, potentially after doing work like starting a retry loop or opening a transaction, or short-circuit and return early. The very last "interceptor" in the chain is effectively the original method body itself, invoked once nothing intercepts further.
Because the proxy class and the interceptor wiring both exist as compiled classes, GraalVM's static analysis sees the whole call chain as ordinary method invocations, avoiding the dynamic class generation that trips up native image with traditional runtime proxying.
More Related questions...