Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
25 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ruslan Stelmachenko
5 years ago

In latest version of IDEA there is option to reload resources on frame deactivation (meaning IDEA window frame).

1. Open “Run/Debug Configurations” window.
2. Find Your Spring Boot configuration and click on it.
3. Click “Configuration” tab.
4. Open “Spring Boot” section.
5. You should see “Running Application Update Policies” item.
6. Set “On frame deactivation:” to “Update resources”.

Now your resources will be updated (copied from src/main/resources to classpath) each time you ALT-TABbing from IDEA window.

PureIllusion
1 year ago

The instructions in the article did not work for IntelliJ IDEA 2022.1 (Ultimate Edition); however, the instructions in this comment worked. Thank you for posting the updated instructions in your comment.

Ville Miekk-oja
6 years ago

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

Eric
2 years ago

This tutorial not working with IntelliJ IDEA 2021.2 (Community Edition).

Following the steps up to 2nd step. Things has changed a little…

compiler.automake.allow.when.app.running has been moved to advance settings according to the following link : https://youtrack.jetbrains.com/issue/IDEA-274903

I still had to go to registry to enable ide.windowSystem.autoShowProcessPopup.

But even with all of this…. my application.properties changes are still not picked up.

Anyone know how to fix this? Thank you

PureIllusion
1 year ago
Reply to  Eric

Follow Ruslan Stelmachenko’s instructions above. They worked for me on 2022.1

Damir
6 years ago

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

Damir
6 years ago
Reply to  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
5 years ago
Reply to  Damir

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

Brad
5 years ago

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!

Sagar
6 years ago

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
6 years ago
Reply to  Sagar

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

janam croods
3 years ago

it’s not working in case of JSP
any Specific reason?
i have refereed this https://www.jetbrains.com/help/idea/spring-support-tutorial.html#changes

Jordan Nelson
3 years ago

https://www.loom.com/share/5168005335624ad196500595f6c5ae51

I am close, but it is still not working on the first time. See video. Weird behavior! If I CMD+Tab to Chrome and refresh, the changes are not there. However, if I CMD+Tab to Chrome, CMD+Tab to IDEA, then CMD+Tab to Chrome and refresh the changes are there. I have on frame deactivation: update resources set. And have followed all instructions.

Hisonookami
4 years ago

Thanks

Amit Kumar
4 years ago

Thanks mykong!!
It helped. 🙂
Just wanted to say please tell how to open compiler setting. The path you mentioned seems to be updated. Pressing shortcut worked for me.

Yury
5 years ago

Thank you very much for so valuable article!!!

Taoiufff
5 years ago

thanks

Antony
5 years ago

It works! Thanks for saving time!

Erycoking
6 years ago

thanks man. it worked.

Ville Miekk-oja
6 years ago

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

Sarah Kelly
7 years ago

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:(

JPB
6 years ago
Reply to  Sarah Kelly

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

mkyong
7 years ago
Reply to  Sarah Kelly

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.