Micronaut Tutorial
Learn Micronaut step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Micronaut? Meet Micronaut, the JVM framework that does dependency injection at compile time: fast startup, low memory, small native images, and where it fits.
- Creating a Micronaut App Create a Micronaut project with the mn CLI or Micronaut Launch, pick the language, build tool and features, and understand what the generator writes.
- Project Structure and Configuration Tour a Micronaut project: the Application class, application.yml, environments, property placeholders and the order in which configuration sources win.
- Your First Controller Write your first Micronaut endpoint with @Controller and @Get, run it with Gradle or Maven, call it with curl, and see how requests are routed to methods.
- Ahead-of-Time Compilation How Micronaut's annotation processors generate bean definitions, introspection and AOP advice during the build, so no reflection or runtime proxies are needed.
Beans and Dependency Injection
- Beans and Singletons Define Micronaut beans with @Singleton, inject them through constructors, fields and methods, choose between implementations, and avoid circular dependencies.
- Qualifiers and Factories Choose between several beans of the same type with @Named, @Primary and custom qualifiers, and create beans from third-party classes with @Factory and @Bean.
- Scopes, Lifecycle and Events Understand Micronaut scopes (@Singleton, @Prototype, @Context, @Refreshable), @PostConstruct and @PreDestroy hooks, and the application event system.
- Conditional Beans Enable beans only when a property, environment, class or other bean is present with @Requires, and swap implementations with @Replaces and @Secondary.
- AOP and Method Interceptors Add logging, caching, retries and timing to Micronaut beans without touching their code, using @Around advice and MethodInterceptor. Includes runnable stand-ins.
HTTP Server and Clients
- Controllers and Routing Map HTTP verbs and URIs to Micronaut controller methods: @Get, @Post, @Put, @Delete, path variables, query values, headers and route precedence.
- Request Binding and Responses Read request bodies, forms and uploads in Micronaut, and build responses with HttpResponse, status codes, headers and content negotiation.
- JSON and Serialization How Micronaut turns objects into JSON and back: Micronaut Serialization with @Serdeable, records, Jackson annotations, naming, dates, nulls and third-party types.
- Declarative HTTP Clients Call other services in Micronaut by writing an interface with @Client and @Get. Learn URI templates, error handling, and see the idea in a runnable Java stand-in.
- Filters and Error Handling Run code around every request with Micronaut HTTP filters, and turn exceptions into clean JSON errors with @Error and ExceptionHandler. Runnable Java stand-ins included.
- Streaming, Server-Sent Events and Async Handle slow work and live data in Micronaut: reactive return types, server-sent events, streaming responses and @ExecuteOn. With runnable Java stand-ins.
Data Access
- Data Sources and Connection Pools Connect a Micronaut app to a database: datasource configuration, HikariCP pool sizing, environments and H2. Runnable JDBC and connection-pool stand-ins on Java.
- Micronaut Data and Repositories Learn Micronaut Data: entities, CrudRepository interfaces, query methods derived from names, and how SQL is generated at compile time. Runnable H2 stand-ins.
- Queries, Pagination and Projections Write explicit @Query methods, page results with Pageable and Page, and return slim DTO projections in Micronaut Data. Runnable H2 stand-ins show the SQL behind them.
- Transactions and Database Migrations Keep data consistent with @Transactional in Micronaut and evolve your schema safely with Flyway migrations. Runnable H2 stand-ins show commit, rollback and a migrator.
- Relationships and Other Data Stores Map one-to-many and many-to-many relations in Micronaut Data, avoid the N+1 query trap, and see where JPA, R2DBC and MongoDB fit. Runnable H2 stand-ins included.
Configuration and Validation
- Configuration Files and Environments How Micronaut loads configuration: application.yml, environment variables, system properties, @Value, @Property and environment-specific files, with runnable Java stand-ins.
- Typed Configuration with @ConfigurationProperties Bind groups of settings to typed Java classes with @ConfigurationProperties, @EachProperty and immutable records. Includes runnable binding stand-ins.
- Bean Validation in Micronaut Validate request bodies, parameters and configuration with Jakarta Bean Validation in Micronaut: constraints, @Valid, @Validated, custom constraints and error responses.
Security
- Security Fundamentals and Access Rules Secure a Micronaut app: the micronaut-security module, @Secured and SecurityRule, role checks, intercept-url-map, anonymous access and a runnable rule-engine stand-in.
- Authentication Providers and Password Storage Write a Micronaut authentication provider, enable the login endpoint, store passwords with salted slow hashes and lock out brute-force attempts. Runnable Java stand-ins.
- JWT Tokens in Micronaut How JSON Web Tokens work and how Micronaut Security issues and validates them: header, claims, HS256 signatures, expiry, refresh tokens and runnable Java stand-ins.
- OAuth 2.0 and OpenID Connect Add login with Google, Keycloak or Okta to Micronaut using OAuth 2.0 and OpenID Connect: authorization code flow, PKCE, resource server setup and runnable flow stand-ins.
Cloud and Serverless
- Service Discovery and Distributed Configuration Register Micronaut services, find them by name with @Client(id), load balance, use Consul and Kubernetes discovery, and share configuration. Runnable stand-ins.
- AWS Lambda and Serverless Functions Build serverless functions with Micronaut: MicronautRequestHandler, API Gateway proxy controllers, cold starts, GraalVM native Lambdas and a runnable handler stand-in.
- Metrics, Health Checks and Tracing Observe a Micronaut service in production: management endpoints, health indicators, Micrometer and Prometheus metrics, OpenTelemetry tracing and logging. Runnable stand-ins.
Testing and Native Images
- Testing with Micronaut Test Write fast Micronaut tests with @MicronautTest, an embedded server, injected HTTP clients, @Property overrides and JUnit 5. Includes a runnable mini test harness stand-in.
- Mocking, @MockBean and Test Resources Replace beans in tests with @MockBean and @Replaces, use Mockito or hand-written fakes, and start real databases with Micronaut Test Resources and Testcontainers.
- GraalVM Native Image Basics Compile a Micronaut app to a native executable with GraalVM: what native image does, nativeCompile, Docker builds, startup and memory gains, trade-offs. Runnable stand-ins.
- Native Image Pitfalls and Reflection Configuration Fix common GraalVM native image problems in Micronaut: reflection, resources, @ReflectiveAccess, @Introspected, serialization, build-time vs run-time init and debugging missing metadata.
Projects and Practice
- Project: A Validated Notes REST API Build a complete Micronaut REST API: records, validation, a repository, a service, controllers, error handling and tests. With a runnable end-to-end Java stand-in.
- Project: A Secured Inventory Service Build a JWT-secured inventory microservice in Micronaut with roles, stock rules, optimistic locking, health and metrics, plus a runnable end-to-end Java stand-in.
- Project: Event-Driven Order Processing Design an order pipeline in Micronaut with application events, Kafka messaging, idempotent consumers, retries and a dead-letter queue, with a runnable Java event-bus stand-in.