Intellij IDEA – Spring boot reload static file is not working

In Eclipse, just include the Spring Boot Dev Tools dependency, then the hot swapping and static file reload will be enabled magically. For Intellij IDE, we need extra steps to enable it.

1. Spring Boot Dev Tools

With Spring Boot Dev Tools enabled :

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

First, include the Spring Boot Dev Tools dependency :

pom.xml

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

2. Build Project Automatically

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

3. Intellij Registry

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

3.2 Find and enabled this option compiler.automake.allow.when.app.running

Done. Now, the hot swapping & static files auto reload should be enabled.

In Menu -> Build -> Build Project (CTRL + F9)
If the static files are not reloaded, press CTRL+F9 to force a reload.

References

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

avatar
9 Comment threads
8 Thread replies
2 Followers
 
Most reacted comment
Hottest comment thread
14 Comment authors
mkyongBradYuryTaoiufffEDUARDO LAGO AGUILAR Recent comment authors
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

Brad
Guest
Brad

What do you mean by you ran as Main-Class? I used the default runner intellij setup and am not getting reloads (after following the tutorial obv).

Thanks!

Yury
Guest
Yury

Thank you very much for so valuable article!!!

Taoiufff
Guest
Taoiufff

thanks

Antony
Guest
Antony

It works! Thanks for saving time!

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”.