Micronaut Framework 2 Upgrade Reference
These historical upgrade notes were migrated from the Micronaut Upgrade Guide archive.
Micronaut Framework 2.5.0
What’s new with 2.5.0
Core Features
IO Stream Support
It is now possible to define a body argument of a controller method with an InputStream. For example @Body InputStream inputStream. Note that you must offload the execution to another thread pool to avoid blocking the event loop when reading the stream. InputStream can also be returned from controller methods.
HTTP to HTTPS redirect with Dual Protocol
If Dual Protocol is enabled, now it is possible to redirect all HTTP requests automatically to the HTTPS port. See more information about how to enable and configure it.
GraalVM 21.1.0 Support
Micronaut has been updated to support the latest GraalVM 21.1.0 release with the Gradle and Maven plugins now defaulting to 21.1.0.
Support for JDK 16 and Gradle 7.0 in Micronaut Launch
Micronaut Launch has been updated with support for JDK 16 and Gradle 7.0.
Random Configuration Values
It is now possible to set a max and a range for random numbers in configuration. For example to set an integer between 0 and 9, ${random.int(10)} can be used as the configuration value. See the documentation under "Using Random Properties" for more information.
Module Upgrades
Micronaut Data 2.4.0
Huge Micronaut Data update including many new features including:
-
Full support for immutable entities. You can use Java 16 records or Kotlin immutable data classes
-
Integrated support for R2DBC, now the
data-r2dbcmodule is a part of the data project and shares the same code with JDBC -
Optimistic locking for JDBC/R2DBC
-
Repositories now support batch insert/update/delete even with a custom query
-
Rewritten entity mapper allows more complex mapping for JDBC/R2DBC entities
-
Support for
@JoinTableand@JoinColumnannotations -
A lot of bugfixes!
Micronaut Micrometer 3.4.0
The Micrometer module has been upgraded and now supports repeated definitions of the @Timed annotation as well as also supporting the @Counted annotation for counters when you add the micronaut-micrometer-annotation dependency to your annotation processor classpath.
Micronaut Oracle Cloud 1.3.0
Micronaut’s Oracle Cloud Integration has been updated with support for Cloud Monitoring and Tracing.
Other Modules
-
Micronaut Security 2.4.2
-
Micronaut Azure 2.2.0
-
Micronaut Aws 2.6.0
-
Micronaut Grpc 2.4.0
-
Micronaut OpenApi 2.4.0
-
Micronaut Kafka 3.3.0
-
Micronaut Flyway 3.6.0
-
Micronaut Liquibase 3.3.1
-
Micronaut Discovery Client 2.4.0
-
Micronaut ElasticSearch 2.3.0
Dependency Upgrades
-
Kafka 2.8.0
-
GraalVM 21.1.0
-
Liquibase 4.3.4
-
Flyway 7.7.3
-
Elasticsearch 7.12.0
2.5.0 Breaking Changes
In previous versions of Micronaut it was possible to read the body of a request in a server filter under some conditions. Reading the request body in a filter has historically been inconsistent because the body is not read in many cases. In Micronaut 2.4, the body was read until the route arguments were satisfied, and then the server filters were executed. This lead to issues with memory leaks in some cases and is inefficient because a filter may skip route execution altogether by not proceeding the chain, thus the body did not need to be read. In Micronaut 2.5 the body will not be read until after filters are executed. This may lead to cases where the body was available in a filter and is no longer available.
Micronaut Framework 2.4.0
What’s new with 2.4.0
Core Features
Jakarta Inject
The jakarta.inject inject annotations are now supported as an alternative to javax.inject. Micronaut 3 will change the default inject annotations to Jakarta, however the javax annotations will continue to be supported if added to your build explicitly.
Micronaut 3 will change the bean context API to return our custom provider contract, api:context.BeanProvider[]. We suggest existing applications to change to use that interface instead of javax.inject.Provider, however both the jakarta.inject.Provider and javax.inject.Provider interfaces will continue to be supported.
Core Nullability Annotations
With the future of JSR-305 unclear and issues with regards to the module system with existing solutions, Micronaut 2.4 will replace usages of Spotbugs with core nullability annotations: ann:core.annotation.Nullable[] and ann:core.annotation.NotNull[].
Existing applications should switch to using these annotations. If other annotations are preferable, the dependency should be added explicitly to your build because no third party Nullable or NonNull annotations will be available transitively in the next major version.
Improvements to Interceptor Binding
Micronaut’s support for AOP interceptors has been improved allowing interceptors to be attached to any annotation through the use of api:inject.annotation.AnnotationMapper[] instances. It is also now possible to bind multiple api:aop.MethodInterceptor[] instances to a single annotation instead of there being a 1-to-1 mapping between annotation and interceptor.
From 2.4.x onwards the recommending way to define AOP advise is to use the ann:aop.InterceptorBinding[] annotation on the annotation you wish to trigger AOP advise:
snippet::io.micronaut.docs.aop.around.NotNull[tags="imports,annotation", indent=0, title="Around Advice Annotation Example"]
Then use ann:aop.InterceptorBean[] on the api:aop.MethodInterceptor[] you wish to bind to the above advise:
snippet::io.micronaut.docs.aop.around.NotNullInterceptor[tags="imports,interceptor", indent=0, title="MethodInterceptor Example"]
Multiple api:aop.MethodInterceptor[] types can bind to a single advise annotation and any given interceptor can bind to multiple annotations.
JSON Error Responses
In previous versions of Micronaut, to control the format of error response bodies, it required replacing all of the existing api:http.server.exceptions.ExceptionHandler[] instances. In Micronaut 2.4, the logic to create error response bodies has been moved to a single bean that implements api:http.server.exceptions.response.ErrorResponseProcessor[]. Now instead of having to replace many beans to have a consistent format, only a single bean needs to be replaced. The default implementation behaves the same as in previous versions to maintain backward compatibility.
Micronaut Data
Support for Java 14+ Records with JDBC
Micronaut Data JDBC now supports using Java 14+ records to represent persistent entities, for example:
package example;
import edu.umd.cs.findbugs.annotations.Nullable;
import io.micronaut.data.annotation.*;
import java.util.Date;
@MappedEntity
record Book(
@Id @GeneratedValue @Nullable Long id,
@DateCreated @Nullable Date dateCreated,
String title,
int pages) {
Book(String title, int pages) {
this(null, null, title, pages)
}
}
Persistence Events Support
Micronaut Data JPA, JDBC and R2DBC now support persistence events on either entities or Micronaut beans. For example:
package example;
import io.micronaut.data.annotation.event.PrePersist;
import javax.inject.Singleton;
@Singleton
public class AccountUsernameValidator {
@PrePersist
void validateUsername(Account account) {
final String username = account.getUsername();
if (username == null || !username.matches(“[a-z0-9]+”)) {
throw new IllegalArgumentException(“Invalid username”);
}
}
}
Integration with Oracle Coherence CE
We are pleased to announce a first milestone release of Micronaut integration with Oracle Coherence Community Edition, which makes implementation of Micronaut applications with a Coherence back end a breeze.
Below are some of the features supported by the various modules within micronaut-coherence project:
Micronaut Data Support
The micronaut-coherence-data module allows you to use Micronaut Data with Coherence as a back-end data store.
Dependency Injection of Coherence-managed Objects
A new micronaut-coherence module provides factories for commonly used Coherence objects, such as Cluster, Session, NamedMap, NamedCache, NamedTopic, and many others, which allows you to easily inject those objects into your application classes.
Listeners for Coherence Events
The micronaut-coherence module also provides support for Coherence server- and client-side events via Micronaut event listeners.
Micronaut Messaging Support
Finally, the micronaut-coherence module provides support for Micronaut Messaging using Coherence Topics.
Micronaut Caching Support
The micronaut-coherence-cache module adds support for using Coherence as a back end for Micronaut Cache.
Micronaut Distributed Config Support
The micronaut-coherence-distributed-configuration module adds support for using Coherence as a store for Micronaut Distributed Configuration.
Micronaut HTTP Sessions Support
The micronaut-coherence-session module adds support for using Coherence as a store for Micronaut HTTP Sessions.
Cloud Features
Easier Configuration of Oracle Cloud Autonomous Database
A new micronaut-oraclecloud-atp has been added that makes it easier to automatically download the Oracle Wallet definition and connect to Autonomous Database on Oracle Cloud.
Support for Oracle Cloud Monitoring via Micrometer
A new micronaut-oraclecloud-micrometer module has been added that adds support for exporting Micrometer metrics to Oracle Cloud.
Official Kubernetes Client
With the new micronaut-kubernetes-client module you can now inject apis objects from the official Kubernetes Java SDK as regular beans.
In Micronaut 3 this new module will be used as primary kubernetes client, making the current one deprecated.
Micronaut AWS
Micronaut AWS now includes the new AWS SDK v2 that has support for GraalVM out of the box. Every service included in the module like S3, Parameter Store, SES, SQS,… is now compatible with Micronaut-GraalVM integration.
Module Upgrades
-
Micronaut Oracle Cloud
1.1.1→1.2.1 -
Micronaut Data
2.2.4→2.3.0 -
Micronaut R2DBC
1.0.1→1.1.0 -
Micronaut Kubernetes
2.2.0→2.3.0 -
Micronaut AWS
2.3.0→2.4.0
Dependency Upgrades
-
Jaeger Version
1.3.1→1.5.0 -
Zipkin Version
2.15.0→2.16.3
2.4.0 Breaking Changes
Methods annotated with @CircuitBreaker that used the includes or excludes members were not functioning correctly. The circuit breaker was opening for exceptions that did not match the supplied exception types. This has been changed to correctly respect the includes and excludes.
Micronaut Framework 2.3.0
What’s new with 2.3.0
Core Features
Banner
A new customizable banner is now displayed when the application starts up. See Micronaut Banner for more information.
Compatibility with GraalVM 21.0.0
This release is compatible with the latest GraalVM 21.0.0 release, updating and testing all modules against the latest version of native image.
Improved Support for Records
Java 14+ Records can now be used to define Configuration Properties. By default when @ConfigurationProperties is used on a record, configuration injection is applied. For example:
package example;
import io.micronaut.context.annotation.*;
import javax.validation.constraints.*;
@ConfigurationProperties(“example”)
record Example(@Min(20) int num, String name) {
}
Bean Introspections Now Support Execution Handles
A api:core.beans.BeanIntrospection[] can now declare methods that should generate reflection-free execution handles. This feature allows calling other methods (besides setters) on introspections without using reflection.
Improved Support for Copy Constructors and Immutable Types
An immutable api:core.beans.BeanIntrospection[] (like Java Records as mentioned above) requires different handling when you need to create a new instance with a particular property modified. A typical pattern for this is to construct a new instance passing all existing values plus the modified value (see for example Lombok’s @With).
Micronaut’s Bean Introspections now support this pattern. For example:
val introspection = BeanIntrospection.getIntrospection(Example.java);
Example example = introspection.instantiate(10, "Test");
assertEquals(10, example.num());
example = introspection.getRequiredProperty("num", int.class)
.withValue(example, 20);
assertEquals(20, example.num());
The new withValue method automatically creates a new instance, populating the existing properties and returning the instance.
Micronaut computes at compile time an efficient copy-constructor approach that only returns a new instance if the value changes.
HTTP Features
Locale Resolution
A new interface api:http.server.util.HttpLocaleResolver[] has been introduced to support resolving a locale from a given request in multiple ways. A java.util.Locale object can now be a parameter to controller and client methods to automatically bind the locale to/from the request. See the documentation for more information.
Host Resolution
It is now possible to validate a resolved host against a list of regular expressions patterns. See the documentation for more information.
Cloud Features
New CI/CD Deployment Workflows for Github Actions in Launch
Micronaut Launch has been updated to include CI/CD workflows to deploy to common container-based Cloud environments including Oracle Cloud Function, Azure Container Instance and Google Cloud Run.
Combined with the ability to Push to Github this makes it a breeze to set up Micronaut applications to be deployed to the Cloud.
Google Cloud Secret Manager
Thanks to a contribution by Vinicius Carvalho, Micronaut GCP supports distributed configuration via Google Cloud Secret Manager.
Micronaut JMS
A new Micronaut JMS module (currently in preview) to support JMS messaging including ActiveMQ and Amazon SQS has been added with full support for GraalVM native image. See the Micronaut JMS documentation for more information.
Other improvements
While Micronaut has always followed the Semantic Versioning principles, our non-stable versioning didn’t match the specification. For example, our snapshots were versioned as 1.2.3.BUILD-SNAPSHOT as opposed to 1.2.3-SNAPSHOT.
Since Micronaut 2.3, all our artifacts' non-stable versions will be like:
-
Snapshots:
1.2.3-SNAPSHOT. -
Milestones:
1.2.3-M1,1.2.3-M2, etc. -
Release candidates:
1.2.3-RC1,1.2.3-RC2, etc.
Module Upgrades
-
Micronaut XML
2.1.0→2.2.1 -
Micronaut Cache
2.2.0→2.3.0 -
Micronaut Security
2.2.2→2.3.0 -
Micronaut Spring
2.1.2→3.2.0 -
Micronaut GCP
3.3.0→3.4.0 -
Micronaut AWS
2.2.5→2.3.0 -
Micronaut OpenAPI
2.2.2→2.3.0 -
Micronaut SQL
3.3.5→3.4.0 -
Micronaut Views
2.1.0→2.2.1 -
Micronaut Test
2.2.1→2.3.2 -
Micronaut PicoCLI
3.1.0→3.2.0 -
Micronaut RabbitMQ
2.2.2→2.3.2 -
Micronaut Flyway
3.1.0→3.3.0 -
Micronaut Kubernetes
2.1.0→2.2.0 -
Micronaut Multitenancy
2.2.3→3.0.0(Group ID changed toio.micronaut.multitenancy) -
Micronaut JMS (new)
1.0.0.M1
Dependency Upgrades
-
PicoCLI
4.5.2→4.6.1 -
Caffeine
2.8.6→2.8.8 -
Netty
4.1.56.Final→4.1.58.Final -
Spring
5.2.9.RELEASE→5.3.1 -
Spring Boot
2.3.4.RELEASE→2.4.0 -
GraalVM
20.3.0→21.0.0 -
Tomcat JDBC
9.0.40→9.0.41 -
Flyway
7.0.4→7.4.0
2.3.0 Breaking Changes
The micronaut.server.multipart.enabled setting previously was not respected for the Netty server implementation. The setting is now honored and if explicitly set to false, all multipart requests will be rejected.
Micronaut Framework 2.2.0
What’s new with 2.2.0
Build Features
Maven Plugin Improvements
The Maven plugin now supports different <packaging> types:
-
jar(default): produces a runnable fat JAR. -
native-image: generates a GraalVM native image. -
docker: builds a Docker image with the application artifacts (compiled classes, resources, dependencies, etc). -
docker-native: builds a Docker image with a GraalVM native image inside.
To package an application, mvn package is the one-stop shop to produce the desired artifact.
It also supports using mvn deploy as the only command required to deploy an application that, depending on the <packaging>:
-
jar(default): will deploy the artifact to a remote repository usingorg.apache.maven.plugins:maven-deploy-plugin:deploy. -
dockerordocker-native: will push the Docker image to the configured Docker registry.
Read more information in the Maven Plugin documentation.
Gradle Plugin Improvements
The Gradle plugin has a new testNativeImage task that builds the GraalVM Native Image and uses the native application as an embedded server enabling the ability to write native integration tests.
Micronaut Launch Enhancements
Support for Kotlin Gradle Builds
It is now possible to create applications that use build.gradle.kts instead of build.gradle using the --build argument of the CLI:
$ mn create-app demo --build gradle_kotlin && cd demo
$ ./gradlew test
Or via the Micronaut Launch API:
$ curl https://launch.micronaut.io/demo.zip?build=gradle_kotlin -o demo.zip && unzip demo.zip -d demo && cd demo
$ ./gradlew test
Push to Github
It is now possible to create an application with and Micronaut Launch and have it pushed automatically to a repository in your Github account. When generating an application just select the "Push to Github" option.
New Micronaut Modules
MQTT Support
Improving the experience in IoT use cases, Micronaut now has integration with MQTT similar to the integration with Kafka and RabbitMQ. See the Micronaut MQTT documentation to get started.
Micronaut Data R2DBC
A new module that adds support for R2DBC (Reactive Database Connectivity) has been added in preview status. Micronaut Data R2DBC lets you define reactive data repositories using R2DBC that work with any of the supported drivers and include support for GraalVM Native Image.
See the Documentation for Micronaut R2DBC for more information.
Module Upgrades
-
Micronaut Acme
2.1.0 -
Micronaut Aws
2.2.3 -
Micronaut Azure
2.1.0 -
Micronaut Cache
2.2.0 -
Micronaut Cassandra
3.1.0 -
Micronaut Data
2.2.0 -
Micronaut DiscoveryClient
2.2.0 -
Micronaut ElasticSearch
2.1.0 -
Micronaut Flyway
3.1.0 -
Micronaut Gcp
3.3.0 -
Micronaut GraphQL
2.2.0 -
Micronaut Groovy
2.2.0 -
Micronaut gRPC
2.2.0 -
Micronaut Hibernate Validator
3.0.0 -
Micronaut Jmx
2.1.0 -
Micronaut Kafka
3.1.0 -
Micronaut Kotlin
2.2.0 -
Micronaut Liquibase
3.0.0 -
Micronaut MQTT
1.0.0 -
Micronaut Micrometer
3.1.0 -
Micronaut Mongo
3.1.0 -
Micronaut NatsIo
2.2.0 -
Micronaut Neo4j
4.1.0 -
Micronaut OpenApi
2.2.0 -
Micronaut Oracle Cloud
1.1.0 -
Micronaut Picocli
3.1.0 -
Micronaut R2DBC
1.0.0.M2 -
Micronaut RabbitMQ
2.2.0 -
Micronaut Reactor
1.1.0 -
Micronaut Redis
3.1.0 -
Micronaut Rss
2.2.0 -
Micronaut Rss
2.3.0 -
Micronaut RxJava3
1.1.0 -
Micronaut Security
2.1.4 -
Micronaut Security
2.2.0 -
Micronaut Servlet
2.1.1 -
Micronaut Sql
3.3.1 -
Micronaut Test
2.2.1 -
Micronaut Views
2.1.0 -
Micronaut Xml
2.1.0
Dependency Upgrades
-
Caffeine
2.8.6 -
Eclipse Paho v3
1.2.5 -
Eclipse Paho v5
1.2.5 -
Elasticsearch
7.9.3 -
Flyway
7.0.4 -
gRPC
1.33.1 -
Hibernate
5.4.23.Final -
Kafka
2.6.0 -
Kotlin Coroutines
1.4.1 -
Ktor
1.4.1 -
Liquibase
4.2.0 -
Lombok
1.18.16 -
Oracle JDBC Driver
19.8.0.0 -
Picocli
4.5.2 -
Protobuf
3.14.0 -
Reactor
3.4.0 -
Swagger
2.1.5
2.2.0 Breaking Changes
Kotlin suspend functions in controllers that return null now correctly respond with a 404. This behavior was inconsistent with other return types in previous versions and returned a 200 OK response.
Micronaut Framework 2.1.0
What’s new with 2.1.0
Core Features
Introspections for JDK 14 Records
It is now possible to define bean introspections on JDK 14+ record types (note these currently require the ––enable–preview flag to the compiler and JVM).
@Client + Kotlin
@Client interfaces now support suspend methods!
Default Environment
Micronaut 2.1 introduces the concept of a default environment. One or more default environments can be set and they will apply if no other environments are explicitly specified or deduced. See the environments documentation for information on how to use this new feature.
@Order Annotation
The ann:core.annotation.Order[] annotation has been added to support supplying bean order for factory methods or for those who prefer the use of annotations over the api:core.order.Ordered[] interface.
Kotlin 1.4
Micronaut now ships with Kotlin 1.4 for those users using Kotlin.
Build Features
New Gradle Plugin
A new Gradle plugin is available that provides a more expressive way to define a Micronaut application and includes awesome new features for GraalVM Native Image and Docker. The minimum required build to build a Micronaut application is now:
plugins {
id 'io.micronaut.application' version '{version}'
}
repositories {
jcenter()
mavenCentral()
}
micronaut {
version = “2.1.0” // The Micronaut Version
runtime “netty” // Using the Netty runtime
}
mainClassName = “example.Application” // Your main class
Building a Native Image is then as simple as:
$ ./gradlew nativeImage
Whilst building a docker image using GraalVM Native Image can be done with:
$ ./gradlew dockerBuildNative
Or to push a native image to a Docker registry
$ ./gradlew dockerPushNative
Web Features
Client Binding API
A new API has been created to allow for binding declarative HTTP client method arguments to an HTTP request. See the documentation for more information.
Websocket Improvements
Query parameters are now respected and bindable in the Micronaut websocket support.
HttpResponse Improvements
Cookies in HTTP responses from the client side are now retrievable on the HttpResponse. These are the cookies found in the Set-Cookie header.
Cloud Features
Support for Oracle Cloud SDK
A new GraalVM Native Image compatible module for Oracle Cloud SDK has been added allowing you to use any part of the Oracle Cloud SDK with Native Image and also enhancing the SDK with RxJava 2 support.
Support for Oracle Function
Support has been added for building Oracle Functions deployable to Oracle Cloud including the ability to compute the functions in native images using GraalVM.
Support for Google Pub/Sub
Thanks to Vinicius Carvalho at Google, Micronaut now features dedicated support for Google Pub/Sub for seamless messaging in Google Cloud.
Support for Google Cloud Log Format
Thanks to Vinicius Carvalho at Google, Micronaut can now output logs in the official JSON format supported by Stackdriver on Google Cloud
Liveness/Readiness Probes
Micronaut’s /health endpoint now allows you to distinguish liveness and readiness probes at the URIs /health/liveness and /health/readiness. Micronaut Launch’s Kubernetes support has been updated to generate a Kubernetes descriptor configured with these probe endpoints by default.
Module Upgrades
-
Micronaut AWS
2.1.0 -
Micronaut Acme
2.0.0 -
Micronaut Azure
2.0.1 -
Micronaut Cache
2.1.0 -
Micronaut Cassandra
3.0.0 -
Micronaut Data
2.0.0 -
Micronaut Elasticsearch
2.0.1 -
Micronaut Flyway
2.1.1 -
Micronaut GCP
3.2.1 -
Micronaut GraphQL
2.1.0 -
Micronaut Groovy
2.1.0 -
Micronaut gRPC
2.0.5 -
Micronaut Ignite
1.0.0.RC1 -
Micronaut Kafka
3.0.0 -
Micronaut Kotlin
2.1.1 -
Micronaut Liquibase
2.1.0 -
Micronaut Micrometer
3.0.1 -
Micronaut Mongo
DB 3.0.0 -
Micronaut Neo4j
4.0.0 -
Micronaut Open
API 2.1.0 -
Micronaut Oracle
Cloud 1.0.0 -
Micronaut Picocli
3.0.0 -
Micronaut RabbitMQ
2.1.0 -
Micronaut Redis
3.0.0 -
Micronaut Security
2.1.0 -
Micronaut Servlet
2.0.0 -
Micronaut Sql
3.1.0 -
Micronaut Test
2.1.0 -
Micronaut Xml
2.0.0
Dependency Upgrades
-
Commons Dbcp
2.8.0 -
Dekorate
1.0.3 -
Elasticsearch
7.8.1 -
Flyway
6.5.4 -
gRPC
1.32.1 -
Hibernate
5.4.21.Final -
Ignite
2.8.1 -
JUnit
5.7.0 -
Kotlin
1.4.10 -
Ktor
1.4.0 -
Liquibase
3.10.2 -
MSSQL Driver
8.4.1.jre8 -
MariaDB Driver
2.6.2 -
Micrometer
1.5.5 -
Mongo Driver
4.1.0 -
Mongo Reactive Driver
4.1.0 -
Neo4j Driver
4.1.1 -
Netty
4.1.52.Final -
Picocli
4.5.1 -
Postgres Driver
42.2.16 -
Redis Lettuce
5.3.4.RELEASE -
Tomcat Jdbc
9.0.38
Micronaut Framework 2.0.0
What’s new with 2.0.0
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:
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 api:inject.InjectionPoint[] instance to any ann:context.annotation.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) {
......
URL parsedUrl = new URL(url) //handle exception
return new DefaultHttpClient(parsedUrl);
} 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 Lambda construction than execution. Therefore, in Micronaut 2.0, you can specify whether you want eager initialization configured for all singletons using the api:context.ApplicationContextBuilder[] interface:
public class Application {
public static void main(String[] args) {
Micronaut.build(args)
.eagerInitSingletons(true) // <b class="conum">(1)</b>
.mainClass(Application.class)
.start();
}
}
-
Setting eager init to true initializes all singletons
It is also possible to just eager init configuration using eagerInitConfiguration which will initialize all ann:context.annotation.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 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:
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 Image 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:
<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 ann:scheduling.annotation.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 ann:http.annotation.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.
|
Note
|
This also applies to @Error routes making it possible to send different error responses for different content types
|
|
Tip
|
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 api:http.client.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 api:http.client.exceptions.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 ann:io.micronaut.management.endpoint.annotation.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:
dependency:io.micronaut.rxjava3:micronaut-rxjava3[]
For Reactor:
dependency:io.micronaut.reactor:micronaut-reactor[]
And legacy support for RxJava 1:
dependency:io.micronaut.rxjava1:micronaut-rxjava1[]
Included within the new RxJava 3 and Reactor modules are variants of api:http.client.RxHttpClient[] called Rx3HttpClient and ReactorHttpClient respectively.
To use the RxJava 3 HTTP client add the following dependency:
dependency:io.micronaut.rxjava3:micronaut-rxjava3-http-client[]
To use the Reactor HTTP client add:
dependency:io.micronaut.rxjava3:micronaut-reactor-http-client[]
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