Intellij IDEA – Spring boot template reload is not working

This article shows you how to enable Spring boot hot swapping in Intellij IDE.

Spring Boot Dev Tools

  1. Any changes to views or resources can be seen in the browser directly, no need restart, just refresh the browser.
  2. Any changes to the code that will restart the Spring container automatically.

1. Spring Boot Dev Tools

Include the following Spring Boot Dev Tools dependency :

pom.xml

  <!-- hot swapping, disable cache for template, enable live reload -->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
  </dependency>

In Eclipse, just include the above “Spring Boot Dev Tools” dependency, then the template reload and hot swapping will work, for Intellij IDE, you need extra steps to enable it.

2. Build Project Automatically

File –> Setting –> Build, Execution, Deployment –> Compiler –> check this Build project automatically

ideaj-spring-boot-dev-tools

3. Intellij Registry

3.1 Press SHIFT+CTRL+A (Win/Lin) or Command+CTRL+A (Mac) to open a pop-up windows, type registry

ideaj-spring-boot-dev-tools-1

3.1 Find and check this option compiler.automake.allow.when.app.running

ideaj-spring-boot-dev-tools-2

Done.

References

  1. Spring Boot Dev Tools

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Ville Miekk-oja
Guest
Ville Miekk-oja

For my Mac, action popup opens when these are pressed: Command + shift + A. Not Command + ctrl + A

Sagar
Guest
Sagar

I tried the solution on Mac and Intellij 2017.2. But unfortunately, it did not work for me.
I am modifying some of the static html files in spring boot application, but those are not reflected in run or even in debug mode. Do I have to somehow specify explicitly to reload?
File I am modifying are under a directory src/main/resources/templates

James Hollowell
Guest
James Hollowell

My *guess* would be you need to add HTML files to the build resource pattern (Settings->Build, Execution, Deployment->Compiler->Resource patterns)

Damir
Guest
Damir

Thanks mkyong!!! Very useful !! Keep posting!!

Damir
Guest
Damir

Tested with actual Intellij IDEA CE 2017.3.5. It works!! You need start Application as Main-Class not mvn target. Nice!

EDUARDO LAGO AGUILAR
Guest
EDUARDO LAGO AGUILAR

Yes, it worked for me but only as Main-Class not mvn, neither gradlew bootRun

Erycoking
Guest
Erycoking

thanks man. it worked.

Ville Miekk-oja
Guest
Ville Miekk-oja

How to hot reload on manual save, when autosave is disabled?

Sarah Kelly
Guest
Sarah Kelly

The Mac instructions for IntelliJ don’t seem to work (and they don’t make sense to me; registry??). Can you or someone else clarify? I really want hot swapping to work. I got used to it when it previously worked, then it seems an upgrade to Spring Boot caused it to stop working:(

mkyong
Guest
mkyong

Yes, you need to hack the IntelliJ registry so that the Spring Boot Dev tools is able to function properly. Tested on Windows and Mac.

P.S Let me know If you have alternatively solution.

JPB
Guest
JPB

Since no one else answered your question all those months ago, I will.

CMD+OPT+SHIFT / brings up the pop-up window, then select “Registry”.

Taoiufff
Guest
Taoiufff

thanks

Antony
Guest
Antony

It works! Thanks for saving time!