1 Introduction

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

Micronaut is developed by the creators of the Grails framework and takes inspiration from lessons learnt over the years building real-world applications from monoliths to microservices using Spring, Spring Boot and Grails.

Micronaut aims to provide all the tools necessary to build full-featured microservice applications, including:

  • Dependency Injection and Inversion of Control (IoC)

  • Sensible Defaults and Auto-Configuration

  • Configuration and Configuration Sharing

  • Service Discovery

  • HTTP Routing

  • HTTP Client with client-side load-balancing

At the same time Micronaut aims to avoid the downsides of frameworks like Spring, Spring Boot and Grails by providing:

  • Fast startup time

  • Reduced memory footprint

  • Minimal use of reflection

  • Minimal use of proxies

  • Easy unit testing

Historically, frameworks such as Spring and Grails were not designed to run in scenarios such as server-less functions, Android apps, or low memory-footprint microservices. In contrast, Micronaut is designed to be suitable for all of these scenarios.

This goal is achieved through the use of Java’s annotation processors, which are usable on any JVM language that supports them, as well as an HTTP Server and Client built on Netty. In order to provide a similar programming model to Spring and Grails, these annotation processors precompile the necessary metadata in order to perform DI, define AOP proxies and configure your application to run in a microservices environment.

Many of the APIs within Micronaut are heavily inspired by Spring and Grails. This is by design, and aids in bringing developers up to speed quickly.

1.1 What’s New?

Micronaut 1.3.7 includes the following changes:

Support for GraalVM 20.0.0

Micronaut supports creating native-images using GraalVM 20.0.0 for both JDK 8 and JDK 11.

Startup and Memory Usage Optimizations

Startup performance and memory usage (20%) have been improved.

Micronaut Data Integration

Micronaut Data has been added to the micronaut-bom and you can now use the CLI to create Micronaut Data projects:

Setting up Micronaut Data JPA

  1. # add --build maven for maven
  2. $ mn create-app myapp --features data-hibernate-jpa

Setting up Micronaut Data JDBC

  1. # add --build maven for maven
  2. $ mn create-app myapp --features data-jdbc

Initial Support for Kotlin Coroutines and Flow

Initial support for Kotlin Coroutines and the Flow type has been added when used as the return type of controller methods.

Thanks to Konrad Kamiński for this contribution.

Immutable @ConfigurationProperties and @EachProperty

Support for immutable @ConfigurationProperties has been added by annotating the constructor of any configuration class with @ConfigurationInject. See the documentation on Immutable Configuration for more information.

@ConfigurationProperties Example

  1. import io.micronaut.context.annotation.ConfigurationProperties;
  2. import io.micronaut.core.bind.annotation.Bindable;
  3. import javax.validation.constraints.*;
  4. import java.util.Optional;
  5. @ConfigurationProperties("my.engine") (1)
  6. public interface EngineConfig {
  7. @Bindable(defaultValue = "Ford") (2)
  8. @NotBlank (3)
  9. String getManufacturer();
  10. @Min(1L)
  11. int getCylinders();
  12. @NotNull
  13. CrankShaft getCrankShaft(); (4)
  14. @ConfigurationProperties("crank-shaft")
  15. interface CrankShaft { (5)
  16. Optional<Double> getRodLength(); (6)
  17. }
  18. }

@ConfigurationProperties Example

  1. import io.micronaut.context.annotation.ConfigurationProperties
  2. import io.micronaut.core.bind.annotation.Bindable
  3. import javax.validation.constraints.*
  4. @ConfigurationProperties("my.engine") (1)
  5. interface EngineConfig {
  6. @Bindable(defaultValue = "Ford") (2)
  7. @NotBlank (3)
  8. String getManufacturer()
  9. @Min(1L)
  10. int getCylinders()
  11. @NotNull
  12. CrankShaft getCrankShaft() (4)
  13. @ConfigurationProperties("crank-shaft")
  14. static interface CrankShaft { (5)
  15. Optional<Double> getRodLength() (6)
  16. }
  17. }

@ConfigurationProperties Example

  1. import io.micronaut.context.annotation.ConfigurationProperties
  2. import io.micronaut.core.bind.annotation.Bindable
  3. import javax.validation.constraints.*
  4. import java.util.Optional
  5. @ConfigurationProperties("my.engine") (1)
  6. interface EngineConfig {
  7. @get:Bindable(defaultValue = "Ford") (2)
  8. @get:NotBlank (3)
  9. val manufacturer: String
  10. @get:Min(1L)
  11. val cylinders: Int
  12. @get:NotNull
  13. val crankShaft: CrankShaft (4)
  14. @ConfigurationProperties("crank-shaft")
  15. interface CrankShaft { (5)
  16. val rodLength: Double? (6)
  17. }
  18. }
1The @ConfigurationProperties annotation takes the configuration prefix and is declared on an interface
2You can use @Bindable to set a default value if you want
3Validation annotations can be used too
4You can also specify references to other @ConfigurationProperties beans.
5You can nest immutable configuration
6Optional configuration can be indicated by returning an Optional or specifying @Nullable

Ability to Configure Log Levels via Properties

Log levels can now be configured via properties defined in application.yml (and environment variables) with the log.level prefix:

  1. logger:
  2. levels:
  3. foo.bar: ERROR

New Micronaut Cache Modules

Micronaut Cache has been updated to support Hazelcast and Ehcache as additional Cache providers.

New Micronaut Jackson XML Module

Support for parsing and serializing to XML has been added with a new Jackson XML module.

  1. implementation("io.micronaut.xml:micronaut-jackson-xml")
  1. <dependency>
  2. <groupId>io.micronaut.xml</groupId>
  3. <artifactId>micronaut-jackson-xml</artifactId>
  4. </dependency>

Thanks to Sergey for this contribution.

Micronaut OpenAPI (Swagger) 1.3 Update

Micronaut OpenAPI has been updated with loads of improvements including the ability to automatically generate UIs for Swagger output as part of your application. Thanks to croudet for this awesome contribution.

The module is also no longer regarded as experimental.

Micronaut Views 1.3 Update

Micronaut Views has been updated to and now features a new view renderer for Soy (Closure Templates). Thanks to Sam Gammon for this contribution.

Micronaut SQL 1.3 Update

Micronaut SQL includes the latest versions of Hibernate and adds support for the Vert.x MySQL and Postgres Clients. Thank you to shenzhou-6 for this contribution.

Micronaut Micrometer 1.3 Update

Micronaut Micrometer has been updated to support Micrometer 1.3.1.

Micronaut Kafka 1.4 Update

Micronaut Kafka 1.4 has been updated to support Kafka 2.4.0

Micronaut Neo4j 1.3 Update

Micronaut Neo4j 1.3 has been updated to support Neo4j Java Driver 1.7.5. In additional a new 2.0.0 version is available that supports Neo4j Java Driver 4.x line which is the latest version (in order to maintain semantic versioning the default is still 1.3 since the latest version includes changes to package names). See the Micronaut Neo4j Documentation for more information.

Micronaut GRPC 1.1 Update

Micronaut GRPC has been updated to the latest versions of GRPC and Protobuf.

@Requires OS

The @Requires annotation now has support for disabling beans based on the current operating system.

  1. @Requires(os=Family.LINUX)

Basic Auth binding support

In the client and server, an argument of type BasicAuth can be used to generate or parse a basic authorization header.

  1. @Post("/login")
  2. String login(BasicAuth basicAuth) {
  3. ...
  4. }

Request Certificate

For SSL requests, the certificate is now available as a request attribute. See HttpRequest#getCertificate

Client Filter Matching By Annotation

Micronaut HTTP clients and client filters can now be matched by the presence of an annotation. Previously only URL matching was supported. See the documentation to get started.

Dependency Upgrades

Required Third Party Dependencies:

  • ASM 7.07.2

  • Caffeine 2.5.62.8.0

  • Jackson 2.9.92.10.1

  • Reactive Streams 1.0.21.0.3

Optional Third Party Dependencies:

  • Micrometer 1.2.11.3.1

  • Mongo Reactive Driver 1.11.01.13.0

  • Neo4j Java Driver 1.7.21.7.5

  • Jaeger 0.35.51.0.0

  • Kafka 2.3.02.4.0

  • Spring 5.1.85.2.3

  • Zipkin/Brave 5.6.55.9.0

  • Groovy 2.5.72.5.8

  • Gradle 5.5Gradle 6.1 (for new applications)

  • Hibernate Core 5.4.6.Final5.4.10.Final

Modules:

  • Micronaut GRPC 1.0.11.1.1

  • Micronaut Kafka 1.2.01.4.0

  • Micronaut Micrometer 1.2.11.3.0

  • Micronaut MongoDB 1.1.01.2.0

  • Micronaut MongoDB 1.1.01.3.0

  • Micronaut Neo4j 1.1.01.3.0

  • Micronaut OpenAPI 1.2.01.3.0

  • Micronaut Redis 1.1.01.2.0

  • Micronaut SQL 1.2.31.3.0

  • Micronaut Views 1.2.01.3.0