If your application does blocking I/O such as communication via JDBC or JPA you should annotate all controllers that interact with these blocking resources with the annotation specifying either the default I/O thread pool or a thread pool that you configure an manage to deal with these blocking interactions. For example:

    Using @ExecuteOn

    Using @ExecuteOn

    1. import io.micronaut.http.annotation.*
    2. import io.micronaut.scheduling.TaskExecutors
    3. import io.micronaut.scheduling.annotation.ExecuteOn
    4. @Controller("/executeOn/people")
    5. class PersonController {
    6. private final PersonService personService
    7. PersonController(
    8. PersonService personService) {
    9. this.personService = personService
    10. }
    11. @Get("/{name}")
    12. @ExecuteOn(TaskExecutors.IO) (1)
    13. return personService.findByName(name)
    14. }
    15. }

    Using @ExecuteOn

    1. import io.micronaut.http.annotation.*
    2. import io.micronaut.scheduling.TaskExecutors
    3. import io.micronaut.scheduling.annotation.ExecuteOn
    4. @Controller("/executeOn/people")
    5. class PersonController (private val personService: PersonService) {
    6. @Get("/{name}")
    7. @ExecuteOn(TaskExecutors.IO) (1)
    8. fun byName(name: String): Person {
    9. return personService.findByName(name)
    10. }
    11. }

    Compilation Error with classes in io.micronaut.cache package

    If your application fails to compile due to missing classes in the io.micronaut.cache you need to add a dependency on a cache implementation, for example the default cache implementation was Caffeine and this can be restored with the following dependency:

    1. implementation("io.micronaut.cache:micronaut-cache-caffeine")

    Compilation Error with classes in javax.annotation package

    If you application fails to compile referencing classes in the javax.annotation package such as @Nullable and @Nonnull you should update your project to instead import from Spot Bugs.

    Some dependencies have new Maven Group IDs so you may need to update your dependency. The following table summarizes changes to group IDs:

    AWS Module Changes

    The AWS functionality (including support for AWS ParameterStore, AWS Route53 and AWS Lambda Function Client) has been moved out of the Micronaut core therefore if you need AWS related functionality you should use the necessary module.

    Kubernetes Discovery Service deprecation

    The class io.micronaut.discovery.kubernetes.KubernetesDiscoveryClient, that was deprecated in Micronaut 1.2, has now been removed from Micronaut 2.0. The replacement is the new Micronaut Kubernetes module, with an improved support for running Micronaut applications in a Kubernetes cluster, including support for Kubernetes’ ConfigMaps, Secrets and more.

    To use the new module, you need to add the following dependency:

    1. implementation("io.micronaut.kubernetes:micronaut-kubernetes-discovery-client")
    1. <dependency>
    2. <groupId>io.micronaut.kubernetes</groupId>
    3. <artifactId>micronaut-kubernetes-discovery-client</artifactId>
    4. </dependency>

    For Micronaut 2.0, we recommend you to use the native Micronaut-based transaction management instead of other alternatives such as Spring Transaction Management.

    You will use and io.micronaut.transaction.annotation.ReadOnly to mark your transaction demarcations.

    To use those annotations, you have to include the micronaut-data-processor dependency in your annotation processor configuration:

    1. annotationProcessor("io.micronaut.data:micronaut-data-processor")

    If you use Hibernate/JPA, you will need to add as well:

    1. implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
    1. <dependency>
    2. <groupId>io.micronaut.data</groupId>
    3. </dependency>

    Then, code such as:

    1. import io.micronaut.spring.tx.annotation.Transactional;
    2. ...
    3. ..
    4. .
    5. @Singleton
    6. public class GenreRepositoryImpl implements GenreRepository {
    7. ...
    8. ..
    9. .
    10. @Transactional(readOnly = true)
    11. public Optional<Genre> findById(@NotNull Long id) {
    12. ...
    13. ..
    14. }
    15. @Transactional
    16. public Genre save(@NotBlank String name) {
    17. ...
    18. ..
    19. }
    20. }

    becomes:

    Micronaut 2 for Groovy Users

    Micronaut 2 defaults to Groovy 3 and Spock 2 both of which include significant changes at the language and testing framework level.

    In the case of Spock 2 the most important change is that Spock 2 deprecates support for JUnit 4 and the associated JUnit 4 test runner and replaces it with JUnit 5 Platform.

    In the case of a Gradle build this change means that when upgrading to Micronaut 2 with Spock 2 you may find your tests don’t execute at all which can give you the false sense of security that the upgrade was successful.

    To ensure your Spock 2 tests run in a Micronaut 2 Gradle build you must add the following configuration to your build.gradle to enable JUnit 5 platform:

    Using JUnit Platform

    1. test {
    2. useJUnitPlatform()

    With this configuration is place your Spock 2 tests will execute correctly.

    Other Breaking Changes