Recently, I was assigned to set up the boilerplate code using (Spring Boot)[spring boot] for an upcoming project. One of the main action items there was enabling a hot reload of code.
I have worked with watchers with different programming languages to enable a hot reload of code. Since Spring boot is such a mature framework, I hoped there will be readily available packages for this.
spring-boot-devtools to the rescue. Yes, there is an available package that you can use to enable a hot reload of the spring boot code. But, unlike other spring boot packages, you can’t directly add this to your
pom.xml file hoping it would run.
In order to make a hot reload of the spring boot application work in IntelliJ you also need to make some additional changes as well. Below are the steps you need to follow to accomplish this.
spring-boot-devtoolsas a dependency in your project’s pom.xml file. If you are using a multi-module approach, then add this to all the modules’ pom.xml files.
- Go to Settings > Build, Execution, Deployment > Compiler and enable
Build project automatically.
- Now, go to Settings > Advanced Settings and enable
Allow auto-make to start even if developed application is currently running.
Note: If you are using an older version of Intellij, then instead of step 3 follow the below steps.
- Press shift twice, go to the Actions tab, search for Registry and click on it.
- Search for
compiler.automake.allow.when.app.runningand enable it.
Once, all the above steps are followed -> Hot reload is enabled for your project. Start the application and make some code changes on the fly. Give this a second and your application will recompile and changes will be reflected.