1.1 What’s New?
Micronaut 2.0.0 includes the following changes:
Core Features
Support for JDK 14
Micronaut has been updated to support JDK 14.
Groovy 3
Micronaut now supports applications written in Groovy 3.
Startup Performance Improvements
Startup time has been further improved in this release with typical startup time for a new application around 20% faster.
Improvements to Bean Introspections
Bean introspections have been improved to support static creator methods, interfaces and enums. This means you can define a bean introspection on an interface with a private implementation such as:
Introspections on interfaces
import io.micronaut.core.annotation.Creator;
@io.micronaut.core.annotation.Introspected
interface Example {
String getName();
@Creator
static Example create(String name) {
return () -> name;
}
}
Support for Analyzing the Injection Point
Micronaut’s Dependency Injection implementation has been improved such that you can now receive an InjectionPoint instance to any @Factory method. This makes it possible to customize how the bean is created based on the annotation metadata at the point at which the bean is injected.
For example consider the following definition:
@Inject @Client("http://foo.com") RxHttpClient client;
A factory method can receive the injection point and create a client based off of the value:
@Bean
protected DefaultHttpClient httpClient(InjectionPoint<?> injectionPoint) {
String url = metadata.stringValue(Client.class).orElse(null);
if (url != null) {
return new DefaultHttpClient(url);
} else {
return new DefaultHttpClient();
}
}
Support for Eager Initialization of Beans
Eager initialization of beans is useful in certain cases, such as on AWS Lambda where more CPU resources are assigned to Lamdba construction than execution. Therefore as for Micronaut 2.0, you can specify whether you want to eager initialization configuration or all singletons using the ApplicationContextBuilder interface:
Enabling Eager Initialization
public class Application {
public static void main(String[] args) {
Micronaut.build(args)
.eagerInitSingletons(true) (1)
.mainClass(Application.class)
.start();
}
}
1 | Setting eager init to true initializes all singletons |
It is also possible to just eager init configuration using eagerInitConfiguration
which will initialize all @ConfigurationProperties beans.
Spot Bugs Instead of JSR-305 Nullable/NonNull Annotations
In Micronaut 1.x the Google distributed JSR-305 annotations library (com.google.code.findbugs:jsr305
) was used to specify @Nullable
and @NonNull
on interfaces of the Micronaut API using the annotations contained within the javax.annotation
package.
Due to the fact that JSR-305 has been cancelled and that this dependency has potential licensing issues (by using the javax
namespace) as well as problems with the cross packages on Java 9+ with the module system Micronaut 2.x switches to the spotbugs-annotations
module provided by the SpotBugs project.
It is recommended users of Micronaut use this API instead (although the javax.annotation.Nullable
and javax.annotation.NotNull
annotations continue to be supported).
CLI Features
New Native CLI
Micronaut’s mn
command for the CLI has been rewritten in Micronaut itself and is now compiled into a native image available on Linux, MacOS X and Windows.
Micronaut Launch
Create Micronaut 2.0 applications without having the CLI installed using curl
:
$ curl https://launch.micronaut.io/demo.zip -o demo.zip
$ unzip demo.zip -d demo
Or by visiting https://launch.micronaut.io in your browser.
Run curl [https://launch.micronaut.io](https://launch.micronaut.io)
for more instructions on how to use the API or visit the OpenAPI documentation.
Diff Command
Run mn feature-diff --features=[FEATURE NAME]
from the root of another Micronaut project to create a diff of the changes that need to be applied to enable the feature. For example:
Using feature-diff
$ mn feature-diff --features=azure-function
--- micronaut-cli.yml
+++ micronaut-cli.yml
@@ -3,4 +3,4 @@
testFramework: junit
sourceLanguage: java
buildTool: gradle
-features: [app-name, application, gradle, http-client, java, junit, logback, netty-server, shade, yaml]
+features: [app-name, application, azure-function, azure-function-http, gradle, java, junit, logback, yaml]
--- host.json
+++ host.json
@@ -1,0 +1,7 @@
+{
+ "version": "2.0",
+ "extensionBundle": {
+ "id": "Microsoft.Azure.Functions.ExtensionBundle",
+ "version": "[1.*, 2.0.0)"
+ }
+}
GraalVM Improvements
Micronaut’s support for GraalVM Native Image has been moved out of experimental status, which solidifies our commitment to continue improving support for native images.
Automatic Static Resource Detection for Native Image
It is not longer necessary to configure static resources for your Native Immage builds. The micronaut-graal
annotation processor will automatically do this for you for all resources found in src/main/resources
.
Improved support for JDBC / Hibernate in Native Image
It is no longer necessary to provide additional GraalVM related configuration to connect to databases via JDBC or Hibernate/JPA. Micronaut includes automatic support for the following drivers with GraalVM Native Image:
Oracle
MariaDB
Postgres
MS SQL
H2
MySQL
Support for Flyway Migrations in Native Image
The Micronaut Flyway module has been updated with GraalVM Native Image support so you can now run database migrations in Native Image.
Support for Native Image in AWS SDK v2
Version 2.0 of the Micronaut AWS module includes support for Native Image for the majority of the v2 AWS APIs including S3, Dynamo DB, SES, SNS, and SQS which will be helpful for those developing native AWS Lambda functions with Micronaut + GraalVM.
Support for jOOQ in Native Image
The Micronaut jOOQ module includes support for Native Image and it’s possible to use it with SimpleFlatMapper.
Support for Redis in Native Image
The Micronaut Redis module includes support for Native Image. There are still some pending uses cases that won’t work because of how Lettuce driver works. Make sure you read the documentation.
Support for Elasticsearch in Native Image
The Micronaut Elasticsearch module includes support for Native Image
Build Improvements
New Maven Parent POM
Micronaut now provides a new parent POM that can be used in Maven projects to get setup quickly:
Using the Maven Parent POM
<parent>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-parent</artifactId>
<version>${micronaut.version}</version>
</parent>
New Maven Plugin
The parent POM mentioned above includes a new Micronaut Maven Plugin that enables automatic application restart during development. Just run the following:
$ ./mvnw mn:run
Whenever you make a change to a class file the server will restart automatically.
Gradle 6.5 Update
For Gradle users who create new applications Gradle 6.5 is used which is compatible with JDK 14.
Better Gradle Incremental Annotation Processing Support
Gradle builds with Micronaut 2 for both Java and Kotlin should be significantly faster thanks to improved support for Gradle incremental annotation processing.
HTTP Features
Support for HTTP/2
Micronaut’s Netty-based HTTP client and server have been updated to support HTTP/2.
See the HTTP/2 documentation for more information on how to enable support for HTTP/2.
Threading Model and Event Loop Group Improvements
Micronaut 2.0 uses a new shared default Netty EventLoopGroup
for server worker threads and client request threads. This reduces context switching and improves resource utilization.
See the HTTP Client Configuration section for information on how to configure the default EventLoopGroup
and add additional `EventLoopGroup’s that are configured per client.
In addition, as of Micronaut 2.0 all operations are by default executed on the EventLoop
and users can optionally use the new @ExecuteOn annotation to specify a named executor to execute an operation on if required (for example to offload blocking operations such as interactions with JPA/JDBC to a specific thread pool).
Support for @RequestBean
It is now possible to bind the properties of a POJO argument to a @Controller
to request parameters, headers and so on using the @RequestBean annotation.
Thanks to Github user asodja for this contribution.
Micronaut Servlet
Micronaut now includes support for creating Servlet applications and users can use the command line to create an application that targets popular Servlet containers:
$ mn create-app myapp --features jetty-server # for Jetty
$ mn create-app myapp --features tomcat-server # for Tomcat
$ mn create-app myapp --features undertow-server # for Undertow
Improved Support for Server-Side Content Negotiation
Micronaut will now correctly handle the HTTP Accept
header and pick the most appropriate route for the specified accepted media types using Server-Side Content Negotiation.
This also applies to @Error routes making it possible to send different error responses for different content types |
To add XML support use the Jackson XML module |
Improved Support for Cloud Foundry
Micronaut will now process the VCAP_APPLICATION
and VCAP_SERVICES
environment variables and treat them as property sources.
Thanks to Fabian Nonnenmacher for this contribution.
HTTP Client Improvements
It is no longer necessary to use @Client(..)
to inject a default RxHttpClient instance. You can now inject the default client simply with:
@Inject RxHttpClient client;
If no host is provided at the time of a request, a NoHostException will be thrown.
API for Proxying Requests
A new API for writing API gateways and proxying requests has been added. See the documentation on the ProxyHttpClient for more information.
Endpoint Sensitivity
It is now possible to control the sensitivity of individual endpoint methods. The @Sensitive annotation can be applied to endpoint methods to allow for some methods to have a different sensitivity than the value supplied to the endpoint annotation.
Improvements to Instrumentation
The Instrumentation mechanism for RxJava 2 has been improved to address issues with MDC and reduce the size of reactive stack traces. Thanks to Denis Stepanov and Lajos Gathy for their contributions in this area.
Kotlin Improvements
Support for KTOR in Micronaut Launch
You can generate a Micronaut + Ktor application from Micronaut Launch or via the command line.
Micronaut Kotlin Extensions
New Kotlin Extension Functions are available that make the Kotlin + Micronaut experience that little bit better.
Serverless Improvements
Support for Google Cloud Function
You can now write Serverless functions that target Google Cloud Function using Micronaut. See the Micronaut GCP documentation and example application for more information.
Support for Microsoft Azure Function
You can now write Serverless functions that target Microsoft Azure using Micronaut. See the Micronaut Azure documentation and example application for more information.
Improvements to Micronaut AWS
Micronaut AWS 2.0.0 includes a number of improvements to support for AWS Lambda and AWS in general including new client modules for AWS SDK 2.0, cold start improvements on Lambda and improvements to the support for Amazon Alexa.
Module Improvements
Micronaut is more modular than ever, with several components now available in separate modules and upgrades to those modules.
Micronaut Cache 2.0.0 Upgrade
Caching has been moved into a separate module and out of micronaut-runtime
. If you need caching (including the annotations within io.micronaut.cache.annotation
) you just need to add the individual module for the cache provider you are interested (for example Caffeine, Redis, Hazelcast etc.).
See the documentation for the Cache module for more information.
Micronaut SQL 2.3.0 Upgrade
Micronaut SQL has been improved to default to Micronaut transaction management (making Spring management optional) and includes support for Jdbi (Thanks to Dan Maas for this contribution).
In addition, support has been added for Oracle Universal Connection Pool. Thanks to Todd Sharp for this contribution.
Micronaut Security 2.0.0 Upgrade
The security module has seen many changes to improve the API and introduce new features to support a wider array of use cases.
See the Security module for more information.
New Reactive Modules
Whilst RxJava 2 remains the default, individual modules for other reactive libraries have been added.
For RxJava 3:
implementation("io.micronaut.rxjava3:micronaut-rxjava3")
<dependency>
<groupId>io.micronaut.rxjava3</groupId>
<artifactId>micronaut-rxjava3</artifactId>
</dependency>
For Reactor:
implementation("io.micronaut.reactor:micronaut-reactor")
<dependency>
<groupId>io.micronaut.reactor</groupId>
<artifactId>micronaut-reactor</artifactId>
</dependency>
And legacy support for RxJava 1:
implementation("io.micronaut.rxjava1:micronaut-rxjava1")
<dependency>
<groupId>io.micronaut.rxjava1</groupId>
<artifactId>micronaut-rxjava1</artifactId>
</dependency>
Included within the new RxJava 3 and Reactor modules are variants of RxHttpClient called Rx3HttpClient
and ReactorHttpClient
respectively.
To use the RxJava 3 HTTP client add the following dependency:
implementation("io.micronaut.rxjava3:micronaut-rxjava3-http-client")
<dependency>
<groupId>io.micronaut.rxjava3</groupId>
<artifactId>micronaut-rxjava3-http-client</artifactId>
</dependency>
To use the Reactor HTTP client add:
implementation("io.micronaut.rxjava3:micronaut-reactor-http-client")
<dependency>
<groupId>io.micronaut.rxjava3</groupId>
<artifactId>micronaut-reactor-http-client</artifactId>
</dependency>
New Micronaut NATS module
A new messaging module for Nats.io has been included in Micronaut core.
See the documentation for Micronaut Nats for more information.
Thanks to Joachim Grimm for this contribution.
Module Upgrades
Micronaut AWS -
1.3.9
→2.0.0.RC1
Micronaut Cache -
1.2.0
→2.0.0.RC1
Micronaut Data -
1.0.2
→1.1.0.RC2
Micronaut GCP -
1.1.0
→2.0.0.RC2
Micronaut gRPC -
1.1.1
→2.0.0.RC1
Micronaut Micrometer -
1.3.1
→2.0.0.RC2
Micronaut Mongo -
1.3.0
→2.1.0
Micronaut Neo4j -
1.3.0
→3.0.0.RC1
Micronaut SQL -
1.3.0
→2.3.0
Micronaut Security -
1.4.0
→2.0.0.RC1
Micronaut Spring -
1.0.2
→2.0.1
Dependency Upgrades
Hibernate
5.4.10.Final
→5.4.16.Final
Groovy
2.5.8
→3.0.3
Mongo Reactive Streams
1.13.0
→4.0.2
Mongo Java Driver
3.12.0
→4.0.2
Jaeger
1.0.0
→1.2.0
Jackson
2.10.3
→2.11.0