What Micronaut is
Micronaut is a framework for server-side Java applications: REST APIs, microservices, command-line tools. It accepts HTTP requests, turns objects into JSON and back, works with a database, checks access rights and calls other services. Its key feature is that it does almost all of its preparation work at compile time, not at startup, so the application starts in about a second and uses little memory.
Work at compile time
A framework has to know which classes are controllers, which objects to pass to whom, and which fields a record has for JSON. Spring finds this out at startup: it scans classes, reads annotations through reflection (inspecting a class while the program runs) and builds proxies. Micronaut does the same in advance, through annotation processors. These are plugins for the javac compiler: while your code compiles, they read annotations and generate extra classes.
For example, for an ArticleController, these files appear in target/classes/com/example/ after the build:
$ArticleController$Definition.class
$ArticleController$Definition$Exec.class
ArticleController.classThe $ArticleController$Definition class is a ready-made "recipe" for creating the controller: which constructor to call and what to pass in. At startup Micronaut simply reads these recipes.
| What the approach gives | Why |
|---|---|
| Fast startup | No need to scan classes and read annotations |
| Low memory | No reflection caches and dynamic proxies |
| Earlier errors | Some mistakes show up at compile time |
| Native builds | Without reflection, GraalVM easily compiles the app into an executable |
How it differs from Spring Boot
The annotations are similar, so moving over from Spring is easy:
| Task | Spring Boot | Micronaut |
|---|---|---|
| Controller | @RestController | @Controller |
| GET route | @GetMapping | @Get |
| Component | @Service, @Component | @Singleton |
| Settings | @ConfigurationProperties | @ConfigurationProperties |
| Repository | Spring Data | Micronaut Data |
| When DI is wired | at startup | at compile time |
The price is that after changing dependencies in pom.xml you sometimes need a full rebuild, and the annotation processors must be registered in the build. Several lessons have a "Common mistake" about this.
Version used in the course
The course targets Micronaut 5.2 and Java 25: Micronaut 5 requires at least JDK 25. The build tool is Maven, tests use JUnit. Check your Java:
java -versionThe command should show version 25 or newer. You do not need to install Maven separately: the project includes the mvnw wrapper, which downloads Maven by itself.
What we will build
Throughout the course we build a REST API for a blog:
- Articles at
/articles: list, search, create, update, delete. - Comments on articles and an H2 database through Micronaut Data JDBC.
- Input validation, error handling, settings.
- An HTTP client, tests, password and JWT login, scheduled jobs, health checks.
- Building a jar, plus an explanation of GraalVM native images.
We will send requests to the API with curl, which is available on Windows 10+, macOS and Linux.
Common mistake
If you run the build on an old Java, Maven fails before it even compiles your code. This is what JDK 16 prints:
java.lang.UnsupportedClassVersionError: io/micronaut/maven/testresources/TestResourcesLifecycleExtension
has been compiled by a more recent version of the Java Runtime (class file version 69.0),
this version of the Java Runtime only recognizes class file versions up to 60.0Class file version 69 means Java 25. Install JDK 25 and make sure the JAVA_HOME variable points to it.