Micronaut Dependency Injection - The stand-alone Setup

In this post, let's explore how to use Micronaut as the Dependency Injection container in a stand-alone Java application. Let's start by creating a stand-alone Java application. I make use of the initialisers provided by Gradle (gradle init command). The application structure looks as follows. ➜ microdemo tree . ├── build.gradle ├── gradle…

Micronaut as Dependency Injection Provider

If you are already familiar with Micronaut, most probably you know it as a framework for developing microservices-based applications. Micronaut support JVM languages Groovy and Kotlin in addition to Java. One of the less known facts about Micronaut is that it can also be used as a dependency injection capability…

Micronaut HTTP Client - Error Flow

We have seen Micronaut BlockingHttpClient in action and how to use exchange and retrieve methods to interact with an HTTP endpoint. What happens if your endpoint returns HTTP status code greater than or equal to 400 (they indicate that it's an error)? To explore this, let's create an endpoint that…

Micronaut - Reloading using Gradle's Continuous Build

I have written about my thoughts on hot loading in general in this post. Micronaut from version 1.2 started supporting continuous build, but you had to manually add the configuration entries to your project. With the 2.0 version, Micronaut supports 'continuous build' out of the box. Both Gradle…

Micronaut HTTP Client - just the response body

In a previous post, we used io.micronaut.http.client.BlockingHttpClient to get response from an HTTP endpoint. We used the exchange method as follows. HttpResponse response = client.toBlocking().exchange("/greeting", String) If you are using Java instead of Groovy, you will pass "String.class" instead of "String".We had…

Micronaut CLI - The JVM Version

A few weeks ago, when I was checking for the versions of a tool on SDKMAN CLI, I noticed the broadcast message that a Micronaut 2 is available. If you are not familiar with SDKMAN already, you may want to take a look at my post on SDKMAN I installed…

Micronaut HTTP Client - Parsing Response

I am using Micronaut 2.0 in this post. You can verify your version using the mn -Version command. Let us generate a controller using the create-controller command provided by the Micronaut CLI as follows. I am launching the CLI from myapp directory. ➜ myapp mn mn> create-controller com.nareshak.…

Micronaut External Config

In one of the previous posts, I described how to have configurations per environment and why it a bad idea to build your jar for every environment. Also we saw how to read configuration values from property sources. Many times you might not be in a position to enumerate your…

Micronaut - A common mistake with the use of @Value

Micronaut provides io.micronaut.context.annotation.Value for injecting value from the property source into a variable. Spring framework also provides a similar annotation. Can you spot the mistake in the below code? package com.nareshak; import io.micronaut.context.annotation.Value; import io.micronaut.http.MediaType; import io.micronaut.…