Prev Next

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.

graph TD A[Method annotated with an Around-based meta annotation] --> B[Annotation processor detects interceptor binding] B --> C[Processor generates a proxy subclass overriding the method] C --> D[Generated method builds a MethodInvocationContext] D --> E[Interceptor chain executed in declared order] E --> F[Final interceptor calls context.proceed] F --> G[Original method body runs]

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.

Micronaut's AOP proxy subclasses are created:
An interceptor continues the chain toward the original method by calling:

More Related questions...

What is Micronaut? What are the key features of Micronaut? What is dependency injection in Micronaut? What are Micronaut beans? What is the purpose of the @Singleton annotation in Micronaut? What are the types of bean scopes in Micronaut? How do you create a Micronaut application? What is Micronaut Launch? What is ahead-of-time (AOT) compilation in Micronaut? What are Micronaut controllers? How do you define a REST endpoint in Micronaut? What is the purpose of the @Inject annotation in Micronaut? What are Micronaut configuration properties? Describe how application.yml is used in Micronaut? What is the Micronaut HTTP Client? Why is Micronaut faster at startup than traditional Spring Boot applications? Why does Micronaut avoid using reflection? How does Micronaut achieve compile-time dependency injection? What is the difference between Micronaut and Spring Boot? What is the difference between @Singleton and @Prototype scope in Micronaut? When should you use @Factory in Micronaut? How does Micronaut Data work? What is the difference between Micronaut Data JDBC and Micronaut Data JPA? How do you implement bean validation in Micronaut? How does Micronaut implement AOP (aspect-oriented programming)? How does Micronaut support reactive programming? What is the difference between a Micronaut declarative HTTP client and the low-level HttpClient? How do you implement client-side load balancing in Micronaut? What is Micronaut's service discovery mechanism? How do you implement retries and circuit breakers in Micronaut? What is the difference between @Client and @Controller in Micronaut? How do you handle exceptions globally in a Micronaut application? What is the purpose of Micronaut's BeanContext and ApplicationContext? How does Micronaut support GraalVM native image compilation? When would you choose Micronaut over Spring Boot for a new project? Explain the internal working of Micronaut's compile-time dependency injection? Explain the lifecycle of a Micronaut bean? Explain the execution flow of an HTTP request in Micronaut? How can you optimize Micronaut application startup time further? How do you troubleshoot slow or failing GraalVM native image builds in Micronaut? What is the difference between Micronaut's bean introspection and Java reflection? Explain the internal working of Micronaut's AOP proxy generation? Explain the internal working of Micronaut Data repository method generation? How do you implement distributed tracing across Micronaut microservices? How do you secure a Micronaut application with JWT authentication? How does Micronaut resolve configuration properties across multiple environments? Explain the internal working of Micronaut's event publishing system? How do you troubleshoot excessive memory usage in a Micronaut native image at runtime? How do you troubleshoot a Micronaut bean that fails to inject due to ambiguous qualifiers? Explain how Micronaut's compile-time architecture influences microservice design decisions in real projects?
Show more question and Answers...


Comments & Discussions