List all available features in the Micronaut CLI (mn)

In the Micronaut CLI mn, we can use mn create-app –list-features to list all available features. Table of Contents 1. List All Feature 2. Filter Features 3. Download Source Code 4. References P.S. Tested with Micronaut 4.7.6 1. List All Feature Terminal mn create-app –list-features This will output a categorized list of features like: Terminal …

Read more

Return ZIP file in a Micronaut Controller

In this tutorial, we will create a Micronaut REST API that generates and returns a ZIP file for download. Table of contents 1. Create a Micronaut Controller 2. Unit Testing the Controller 3. Run the Application 4. Download Source Code 5. References Technologies used: Java 21 Micronaut 4.7.6 Maven 3.9.6 1. Create a Micronaut Controller …

Read more

How to Run Startup Code When Micronaut Starts

When building applications with Micronaut, we often need to execute some logic when the application starts. This could include tasks like initializing resources, seeding a database, or logging system information. In this article, we will explore how to run startup code in Micronaut using ApplicationEventListener and @EventListener. Table of contents 1. Implements ApplicationEventListener to Run …

Read more

Return JSON in a Micronaut Controller

In this tutorial, we will learn how to return JSON in a Micronaut controller using simple and practical examples. Table of contents 1. Setting Up the Micronaut Project 2. Returning a JSON Object Define a Data Model What is @Serdeable? Create a Controller Run the Application 3. Returning a List of JSON Objects Run the …

Read more

Micronaut – Loading external yaml or configuration file

In this tutorial, we will explore how to load an external YAML file in a Micronaut application. Table of contents 1. Why Load External Configuration Files? 2. Defining an External YAML File 3. Configuring Micronaut to Load the External YAML File Using Command Line Argument Using Environment Variable 4. Accessing Configuration Values in Micronaut Using …

Read more

Micronaut @ConfigurationProperties Example

Micronaut provides a powerful way to manage configuration using @ConfigurationProperties. This annotation allows us to bind external configuration properties (such as values from application.yml or application.properties) directly to Java objects. Table of contents 1. Setting Up the Micronaut Project 2. Defining Configuration in application.yml 3. Setting Up the Configuration 4. Injecting the Configuration into a …

Read more

Micronaut @ConfigurationBuilder Example

Micronaut @ConfigurationBuilder allows us to bind configuration files to Java objects using builder pattern. Table of contents 1. Defining Configuration in application.yml 2. Builder Pattern 3. Using @ConfigurationBuilder 4. Injecting the Configured Database 5. Running the Application 6. Unit Tests 7. Download Source Code 8. References Technologies used: Java 21 Micronaut 4.7.6 Maven 3.x 1. …

Read more

Return XML in a Micronaut Controller

In this tutorial, we will learn how to return XML responses in a Micronaut application using Jackson XML. Table of contents 1. Setting Up the Micronaut Project Add Jackson XML Dependency 2. Creating the XML Model 3. Creating a Controller to Return XML 4. Running and Testing the Application 5. Writing Unit Tests 6. Download …

Read more

How to Change the Default Micronaut Server Port

By default, a Micronaut application runs on port 8080. In this guide, we will explore multiple ways to change the default Micronaut server port. Table of Contents: 1. Changing the Server Port in application.yml 2. Changing the Server Port in application.properties 3. Setting the Port Using Environment Variables 4. Setting a Random Port 5. Download …

Read more