Enable Hot Reload of Spring Boot Application in IntelliJ

Save time and effort by enabling a hot reload of spring boot application in IntelliJ Idea. This will allow your code changes to reflect without having to restart your application.

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.

Here comes 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.

  1. Add spring-boot-devtools as 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.
<dependency>  
   <groupId>org.springframework.boot</groupId>  
   <artifactId>spring-boot-devtools</artifactId>  
   <scope>runtime</scope>  
   <optional>true</optional>  
</dependency>
  1. Go to Settings > Build, Execution, Deployment > Compiler and enable Build project automatically.
  2. 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.

Intellij Idea open Registry

  • Search for compiler.automake.allow.when.app.running and enable it.

Intellij Idea enable auto make

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.