Creating Your First Micronaut Application

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!

Creating Your First Micronaut Application

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:

ToolVersionInstall Link
Java17 or higher (Java 21 recommended)Adoptium
Micronaut CLILatestMicronaut Installation Guide
GradleBundled (no need to install separately)N/A
IDEIntelliJ 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:

Verify installation

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:

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

Explanation

  • @Controller("/greet") — base URL path.
  • @Get("/{name}") — accepts name 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

🎉 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:

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:

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.