Introduction
Micronaut is a modern, cloud-native Java framework built for microservices and serverless applications. Unlike traditional Java frameworks, Micronaut focuses on:
- Fast startup times
- Low memory consumption
- Compile-time dependency injection
In this tutorial, you will create your first Micronaut application from scratch using the package name com.kscodes.micronaut
. Don’t worry — no prior experience with Micronaut is required!

Why Micronaut?
Before we jump into coding, let’s understand why many developers choose Micronaut:
- Minimal runtime overhead.
- No reflection — faster and safer.
- Built-in support for reactive programming.
- Great for microservices architecture.
- Excellent integration with cloud services.
Prerequisites
Before we begin, make sure you have the following:
Tool | Version | Install Link |
---|---|---|
Java | 17 or higher (Java 21 recommended) | Adoptium |
Micronaut CLI | Latest | Micronaut Installation Guide |
Gradle | Bundled (no need to install separately) | N/A |
IDE | IntelliJ IDEA / Eclipse / VS Code |
For a maven based project you can go through the Installing Micronaut CLI and Setting Up Your First Project
Step 1 — Install Micronaut CLI
Install via SDKMAN
If you use SDKMAN, installation is super easy:
1 2 |
sdk install micronaut |
Verify installation
1 2 3 4 |
mn --version |
Step 2 — Generate Micronaut Application
Now let’s scaffold your first Micronaut application.
mn create-app com.kscodes.micronaut.demo –build=gradle –lang=java
com.kscodes.micronaut.demo
— package name--build=gradle
— Gradle as the build system--lang=java
— language is Java
✅ Tip: You can replace
demo
with your project name.
Step 3 — Understanding Project Structure
Micronaut will generate a ready-to-use project:
1 2 3 4 5 6 7 8 9 10 11 12 |
demo/ ├── build.gradle ├── src/ │ ├── main/ │ │ ├── java/com/kscodes/micronaut/demo/ │ │ │ └── Application.java │ └── test/ ├── gradlew └── README.md |
Step 4 — Writing Your First REST Endpoint
Let’s build a simple greeting API.
Create Controller
Create a new file:src/main/java/com/kscodes/micronaut/demo/GreetingController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.kscodes.micronaut.demo; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; @Controller("/greet") public class GreetingController { @Get("/{name}") public String greet(String name) { return "Hello, " + name + "!"; } } |
Explanation
@Controller("/greet")
— base URL path.@Get("/{name}")
— acceptsname
as a path parameter.- Returns a greeting message.
Step 5 — Run the Application
Start the application:
gradlew run
Step 6 — Test the API
Open your browser or API tool (Postman, Curl, etc.)
http://localhost:8080/greet/John
Response
1 2 3 4 |
Hello, John! |
🎉 Congratulations! You’ve successfully created your first Micronaut REST API.
Step 7 — Add Health Check
Micronaut provides built-in health endpoints.
Enable Management Endpoints
Add to src/main/resources/application.yml
:
1 2 3 4 5 6 7 8 9 10 |
micronaut: application: name: demo server: port: 8080 endpoints: health: enabled: true sensitive: false |
Now visit:
http://localhost:8080/health
You’ll see health information for your app.
Step 8 — Build a Fat JAR
To package the application for deployment:
1 2 3 |
gradlew assemble |
The fat JAR will be in:
build/libs/
Step 9 — Where to Go Next
Now that you have your basic Micronaut app running, you can explore:
- Micronaut Data — for database access.
- Micronaut Security — for authentication/authorization.
- Micronaut Messaging — for Kafka/RabbitMQ integration.
- Deploy to Cloud — AWS Lambda, Google Cloud Functions, Azure Functions.
Conclusion
Micronaut simplifies microservices development while keeping things blazing fast and memory-efficient. You’ve successfully:
- Installed Micronaut CLI
- Created your first Micronaut app
- Built and tested a REST API
From here, the Micronaut ecosystem offers a huge set of features to explore.