{{announcement.body}}
{{announcement.title}}

Building Microservices With Micronaut

DZone 's Guide to

Building Microservices With Micronaut

For initial development, we are leveraging a JAX-RS based microservice-starter application similar to implementation using Oracle Helidon.

· Microservices Zone ·
Free Resource

Micronaut is a modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications. 

For initial development, we are leveraging a JAX-RS based microservice-starter application similar to implementation using Oracle Helidon.

More about the lifecycle is explained below.

You may also like: A Quick Guide to Microservices With the Micronaut Framework

Packaging

Micronaut uses a maven shade plugin for packaging the application which put all the runtime dependencies an uber jar.

XML


Deployment

Micronaut supports HTTP deployment based on netty server and partial/compatible support for JAX-RS resources.

XML
 




xxxxxxxxxx
1
15


 
1
<dependencies>
2
  <dependency>
3
    <groupId>io.micronaut.jaxrs</groupId>
4
    <artifactId>micronaut-jaxrs-server</artifactId>
5
    <version>1.0.0.M1</version>
6
  </dependency>
7
  <dependency>
8
    <groupId>io.micronaut</groupId>
9
    <artifactId>micronaut-runtime</artifactId>
10
  </dependency>
11
  <dependency>
12
    <groupId>io.micronaut</groupId>
13
    <artifactId>micronaut-http-server-netty</artifactId>
14
    </dependency>
15
</dependencies>



In addition to these, it required additional plugins/dependencies at the compile phase to process its annotations.

XML
 




xxxxxxxxxx
1
14


 
1
<annotationProcessorPaths>
2
  <path>
3
    <groupId>io.micronaut</groupId>
4
    <artifactId>micronaut-inject-java</artifactId>
5
  </path>
6
  <path>
7
    <groupId>io.micronaut</groupId>
8
    <artifactId>micronaut-validation</artifactId>
9
  </path>
10
  <path>
11
    <groupId>io.micronaut.jaxrs</groupId>
12
    <artifactId>micronaut-jaxrs-processor</artifactId>
13
  </path>
14
</annotationProcessorPaths>



Launcher

Micronaut provides a build-in runner class that can be invoked through the main class.

Java
 


Which can be a trigger in multiple ways.

Dev

mvn exec:java

Prod

java - jar target/microservice-starter-micronaut.jar

The complete example can found here at microservice-starter-microanaut.


Further Reading

"Hello, Micronaut" Using Microstarter.io

Hello, Micronaut

Micronaut Tutorial: Server Application

Topics:
http ,maven ,micronaut ,microservice ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}