Goodbye Grails, Hello Micronaut #9: Micronaut Application

This is the ninth post in a series that will guide you through the migration from Grails to Micronaut. This guide requires your application to be based on Grails 4.x or later.

In this stage, we should have all the necessary parts of the application migrated. Now the time has come to create the new Micronaut application.

Let's create a new project with -mn suffix such as hello-mn under apps subfolder with a build file hello-mn.gradle similar to the following one:

The subproject can contain a single class that will launch the application:

Pay attention to the package declaration, otherwise, the domain classes cannot be found.

If you want to run the application you can create a Docker Compose file for the database inside hello-mn directory:

MariaDB is used in this example to increase the compatibility with the latest Apple Silicon chips.

And you will also need to create the basic configuration file in src/main/resources/application.yml file:

You can also create a class to preload some example data into the database:

The class implements ApplicationEventListener<ApplicationStartupEvent> to execute the code right after the application has started successfully.

When you run the docker compose file from the hello-mn directory:

docker compose up -d

Then you should be able to run the application from the root of the project:

./gradlew :hello-mn:run

When you query the server from either cURL or some HTTP client then you should get the default result:

curl http://localhost:8080/vehicle/1# {"id":1,"name":"The Box","make":"Citroen","model":"Berlingo"}

Now the time has come to revisit the rest of the contents of the Grails application. We are now free to remove the controllers and their tests.

We usually still have the application.groovy file to be migrated into series of application.yml. Beware of environment { ... } blocks that are not supported in Micronaut — you need to migrate to separate application-development.yml and application-production.yml files.

Please, let us know which other parts have been left in the old Grails application and we try to cover them in apendicies.

Although the Micronaut application is up and running there is the very last step to migrate the database implementation from GORM to Micronaut.

Table of Contents

  1. Multiproject
  2. Configuration
  3. Static Compilation
  4. Datasets
  5. Marshalling
  6. Domain Classes
  7. Services
  8. Controllers
  9. Micronaut Application
  10. Micronaut Data

Sources & Discussion



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store