Enable Automatic Hot Reload in Spring Boot with DevTools
This guide shows how to add Spring Boot DevTools, configure Maven and IntelliJ IDEA, and use both manual and automatic hot‑deployment techniques—including registry tweaks and template cache settings—to achieve instant code changes without restarting the application.
Add DevTools Dependency
Include the Spring Boot DevTools dependency in your pom.xml and set optional to true so it is not packaged for production.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>For a web UI, also add the starter dependencies for Spring MVC and Thymeleaf.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>Configure Maven Build
Enable the DevTools restart classloader by adding fork configuration to the Spring Boot Maven plugin.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>IntelliJ IDEA Settings
Open Settings → Compiler and enable Build project automatically . This allows IDEA to compile changes without a manual build, but it only works when the application is not running.
If the app is running, IDEA will not auto‑build; you must trigger a build manually.
Manual Hot Deployment
After the above setup, you can press Ctrl+F9 (or use the Build → Build Project menu) to compile and trigger a hot reload. The console will show DevTools‑related messages.
Automatic Hot Deployment
To let IDEA rebuild even while the application is running, open the Registry (Windows shortcut Ctrl+Shift+Alt+/) and enable Compiler autoMake allow when app running . Restart IDEA, then any code change will be compiled and redeployed within seconds.
On macOS you can assign a custom shortcut to the same Registry entry via the Keymap settings.
Comparison of the Two Approaches
The manual method gives you explicit control over when a reload occurs, suitable for batch changes. The automatic method continuously rebuilds, which can be convenient but may trigger unnecessary restarts.
How DevTools Works
DevTools uses two classloaders: a base classloader for unchanged libraries and a restart classloader for application classes. When code changes, the restart classloader is discarded and recreated, avoiding a full JVM restart and speeding up the feedback loop.
Additional Tips
If you use template engines like Thymeleaf or FreeMarker, disable their caches during development to see changes instantly:
spring.thymeleaf.cache=falseRemember to re‑enable caching before deploying to production.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
