Spicy Spring: Reload Classes Spring Boot With Spring Loaded And Gradle Continuous Build
When we develop a Spring Boot application we can hot reload newly compiled classes using Gradle. The bootRun
task of the Spring Boot Gradle plugin has support for Spring Loaded. We must add a dependency to Spring Loaded as a dependency for the classpath
configuration in the buildscript
block. If we now use the bootRun
task everything is ready to reload changed classes. Now we can use the continuous build feature of Gradle to listen for changes in our source files to recompile them. The recompiled classes are then reloaded in the running Spring Boot application started with bootRun
. We start a second Gradle instance with the -t
option for the classes
task. This way when we change a source file it gets recompiled automatically and reloaded.
The following build script shows how we add Spring Loaded: