Java / Micronaut Interview questions
How does Micronaut achieve compile-time dependency injection?
Micronaut hooks into the standard Java annotation processing API, the same mechanism used by tools like Lombok, during compilation. Its processor scans source for DI-related annotations such as @Singleton, @Inject, @Prototype, @Factory, and qualifiers, and builds an in-memory model of every bean candidate and its dependencies.
From that model, it generates a companion definition class per bean containing the actual instantiation logic: which constructor to call, which arguments to resolve from the context, and which fields or methods to invoke afterward. These generated classes are compiled into your JAR alongside your own classes.
At runtime, the ApplicationContext loads these definition classes via a lightweight service-loader-style index, not by scanning the classpath for annotated classes, and executes their generated logic directly to construct the object graph.
More Related questions...