ShoutLoudz
Published in

ShoutLoudz

Introduction to Micronaut

Micronaut Framework
Photo by Georg Arthur Pflueger on Unsplash

In this article, we are going to discuss.

  1. What is Micronaut
  2. How to create a basic Micronaut application
  3. Comparison between Micronaut and Spring boot

So let's start…

What is Micronaut:

Micronaut is an open source JVM-based framework for developing web applications, which is lightweight and uses very less memory. Its main feature is it takes very less time to start an application. It does 100% dependency injection at compile time because it analyses metadata at compile time and based on that it will DI and AOP.

Micronaut is very much friendly with Microservices because it has a lot of inbuilt features of Microservices like service discovery, client-side load balancing, authentication

Micronaut is developed basically keeping in mind the latest technologies like cloud computing, serverless, and microservices

How to create a basic Micronaut application:

So For creating a Micronaut application we can use Maven and Gradle build tools.

Steps to create a Hello World App.

  1. Visit the Maven or Gradle link for downloading the respective application.
  2. Alternatively, If we want to create an application we can create it by Micronaut CLI.
  3. After this import, the application on IntelliJ IDE and after specifying port run the application.
micronaut:
application:
name: micronautguide
server:
port: 8086

The syntax is almost similar to Spring boot with very basic differences. The basic syntax for creating a controller with GET method.

@Controller("/hello")
public class HelloController {
@Get
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return "Hello World";
}
}

For Post method we need to add hibernate validator for validation of request objects. Here is an example of the POST Method.

List<Employee> employees = new ArrayList<>();
@Post
public Employee add(@Body @Valid Employee employee) {
employee.setId(employees.size() + 1);
employees.add(employee);
return employee;
}

Netty is the default server of Micronaut.

Comparison between Micronaut and Spring boot:

Both Micronaut and Spring boot are very popular for creating applications. Some points which we can discuss

  1. Project Setup and Language Support: It is very easy to create both Micronaut and Spring Boot applications and IntelliJ Idea is the IDE which supports both frameworks, Java, Groovy and Kotlin languages support these frameworks.
  2. The default server in Spring Boot is Tomcat and Netty in Micronaut.
  3. For messaging we can use Queues in both frameworks.
  4. Spring Boot offers five authorization strategies: basic, form login, JWT, SAML, and LDAP. If we’re using Micronaut, we have the same options except for SAML Both support Oauth2 as well.
  5. Micronaut is natively designed for cloud support and Microservices but Spring boot uses third parties for this.
  6. Spring Boot startup time is in seconds but in micronaut, it is in milliseconds. Memory usage is also very low in Micronaut as compared to spring boot.

So that's all for this post, All the basic things about Micronaut In the next post we will be developing some Microservices using Micronaut.

Thanks for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chakresh Tiwari

Chakresh Tiwari

464 Followers

Software Engineer at Cisco , Sharing my knowledge and experience related to work. I am here to help learners to prepare for tech interviews