Unravel โบ Java concepts โบ Jakarta and other frameworks
Micronaut applications
Micronaut is a JVM framework with dependency injection and AOP done at compile time instead of runtime reflection.
At a glance
Spring reads the wiring diagram when the building opens; Micronaut has the electrician wire everything before the building is handed over, so opening day is quick.
- 1Controllers look like Spring MVC with different names: @Controller("/orders"), @Get("/{id}"), @Post, @Body, and return HttpResponse or plain objects
- 2Beans use jakarta.inject annotations: @Singleton, @Inject, plus @Factory classes with @Bean methods@Requires(property = "feature.x") conditionally creates beans, like Boot conditions.
- 3Declarative clients: @Client("/inventory") interface InventoryClient { @Get("/{sku}") Stock get(String sku); }, implemented at compile time
- 4Configuration objects use @ConfigurationProperties("app.mail") with typed fields, validated at startup
- Compile-time processing means annotation processors must be on the build path (annotationProcessor in Gradle, annotationProcessorPaths in Maven)
- Blocking operations belong on the I/O-separated executor: @ExecuteOn(TaskExecutors.BLOCKING) (default for non-reactive controllers in recent versions)
- Annotation processors generate bean definition classes and AOP proxy subclasses during compilation
@Controller("/orders")public class OrderController { private final OrderService service; public OrderController(OrderService service) { this.service = service; } @Get("/{id}") public HttpResponse<Order> get(long id) { return service.find(id).map(HttpResponse::ok).orElse(HttpResponse.notFound()); }}- line 9 uses Get, the core of Micronaut applications
Read the full explanation (about 1 min)
Micronaut is a JVM framework with dependency injection and AOP done at compile time instead of runtime reflection. That gives low memory use and fast startup, which suits microservices and serverless functions.
A mental model
Spring reads the wiring diagram when the building opens; Micronaut has the electrician wire everything before the building is handed over, so opening day is quick.
How it works
Controllers look like Spring MVC with different names: @Controller("/orders"), @Get("/{id}"), @Post, @Body, and return HttpResponse or plain objects.
Beans use jakarta.inject annotations: @Singleton, @Inject, plus @Factory classes with @Bean methods. @Requires(property = "feature.x") conditionally creates beans, like Boot conditions.
Declarative clients: @Client("/inventory") interface InventoryClient { @Get("/{sku}") Stock get(String sku); }, implemented at compile time.
Configuration objects use @ConfigurationProperties("app.mail") with typed fields, validated at startup.
Going deeper
Compile-time processing means annotation processors must be on the build path (annotationProcessor in Gradle, annotationProcessorPaths in Maven). A missing processor results in beans that are simply not found at runtime.
Blocking operations belong on the I/O-separated executor: @ExecuteOn(TaskExecutors.BLOCKING) (default for non-reactive controllers in recent versions).
The tradeoff compared with Spring is a smaller ecosystem and less community material. Syntax overlap makes it easy to confuse annotations from the two frameworks in one file.
Under the hood
Annotation processors generate bean definition classes and AOP proxy subclasses during compilation. At runtime the ApplicationContext loads those definitions through service loader files and instantiates beans directly, avoiding classpath scanning and reflection and making GraalVM native image straightforward.
Common mistakes
- Missing annotation processor configuration.
- Mixing Spring annotations into Micronaut code.
- Blocking the event loop.
- Expecting runtime-only dynamic features that need reflection.
How Unravel recognises it
When you paste code, Unravel looks for these signs of micronaut applications. Spotting them yourself is a good habit when you read unfamiliar code:
- Annotations:
@MicronautTest@Introspected@Executable@EachProperty@EachBean@Requires@Factory@Replaces@ConfigurationReader@Client@Get@Post@Body@QueryValueand 3 more - Types:
MicronautBeanContext
Part of a learning path
- Jakarta EE and other frameworks ยท previous: Quarkus applications ยท next: Vert.x verticles and the event loop
Related concepts
Frequently asked questions
What is Micronaut applications?
Micronaut is a JVM framework with dependency injection and AOP done at compile time instead of runtime reflection. That gives low memory use and fast startup, which suits microservices and serverless functions.
What are the most common mistakes with Micronaut applications?
Missing annotation processor configuration. Mixing Spring annotations into Micronaut code. Blocking the event loop. Expecting runtime-only dynamic features that need reflection.
How can I see Micronaut applications in real code?
Paste your own Java into Unravel and it will point out where micronaut applications appears, explain how it works at the detail level you choose, and draw the flow of the code around it.