• ClassLoader Reloading - Class Loader based reloading is a popular solution used by most JVM frameworks, however it once again can lead to cached / stale classes, memory leaks and weird errors if the incorrect classloader is used at any moment.

    Given the problems with existing solutions and a lack of a way built into the JVM to reload changes, the safest and best solution to reloading, and the one recommended by the Micronaut team, is to use automatic application restart via third-party tool.

    Micronaut’s startup time is fast and automatic restart leads to a clean slate without potential hard to debug problems cropping up or memory leaks.

    First configure your application.yml file to enable file watch:

    Configuring File Watch

    By setting what happens is that Micronaut will fire a if any file is changed. Setting micronaut.io.watch.restart tells Micronaut to stop the server if a file is changed.

    The native JVM implementation of the interface for Mac OS X using polling which is slow. To improve file watch performance add the following dependencies to your build if you are using OS X:

    Gradle - Configuring Native File Watch on Mac OS X

    Once set to the micronaut.io.watch.restart setting will stop the server when a file changes, it is then up to an external process to restart the server. For example, with Gradle this can be achieved with a continuous build:

    Automatic Restart with Gradle Continuous Build

    Maven does not have an equivalent feature, however you can achieve a similar effect with a bash script:

    Automatic Restart with Maven and Bash

    If automatic restart is for some reason not your preferred approach then you can use most JVM agents with Micronaut. See the following sections for a description on how to setup JVM agents.