Before we start discussing Micronaut, first we have to understand that why we need to use another framework though there are different frameworks already available to support Java Enterprise Software development.
So, the concise answer is “memory footprint” (or more efficient framework), but how we have reached this conclusion that it will be better in few terms compared to other frameworks and when to utilize this one. We will see about this in the coming sections. First, we will start with a sample application and compare its footprint
It’s pretty straightforward, please follow the instructions on https://micronaut.io/download/ various ways differ based on your OS.
Sample(with Windows and Chocolatey)
once the installation is complete you will be equipped with Micronaut CLI and you will see the prompt as shown above. Now, the easiest way to create a controller application is with the below command (-b flag is for build tools (maven or gradle ))
After executing above command we are now ready with our first sample of micronaut application which will generate a sample response .The sample code will look something like this.
Annotations are quite similar to spring framework ,it’s easy to learn and adapt as well.Above example can be executed on embedded netty server .
Now ,we will see the typical memory utilization of Spring sample rest controller and the memory utilization of rest controller of we just created in the above example ,we will utilize the VisualVM for the memory utilization comparison
We can observe here that memory utilization is bit low when we just try to do small and simpler stuff and that can be visible more when we will try more complex examples . But the conclusion here is Micronaut is a framework which is elegant and lightweight for cloud native and microservice development.Code of the above example is present in GitHub
If you are designing an application where you have to be extra cautious about the memory and you will exchanging huge data with different entities and want your services to be easily testable then you need to Micronaut at such places ,there are other good features as well ,but since we are already into cloud era ,memory footprints will surely be deciding factor while deciding about the application architecture .