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
If the static files are not reloaded, press
CTRL+F9
to force a reload.
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.
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.
For my Mac, action popup opens when these are pressed: Command + shift + A. Not Command + ctrl + A
Thanks, article is updated.
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
Follow Ruslan Stelmachenko’s instructions above. They worked for me on 2022.1
Thanks mkyong!!! Very useful !! Keep posting!!
Tested with actual Intellij IDEA CE 2017.3.5. It works!! You need start Application as Main-Class not mvn target. Nice!
Yes, it worked for me but only as Main-Class not mvn, neither gradlew bootRun
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!
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
try CTRL+F9 to force a reload.
My *guess* would be you need to add HTML files to the build resource pattern (Settings->Build, Execution, Deployment->Compiler->Resource patterns)
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
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.
Thanks
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.
Thank you very much for so valuable article!!!
thanks
It works! Thanks for saving time!
thanks man. it worked.
How to hot reload on manual save, when autosave is disabled?
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:(
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”.
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.