When building modern applications with Spring Boot, developers often make frequent changes to code, configurations, and templates. Restarting the application manually after each change can slow down productivity. Enter Spring Boot DevTools—a module designed to accelerate development by enabling hot reload, auto restart, and more.
What is Spring Boot DevTools?
spring-boot-devtools
is a development-time tool that provides:
- Automatic application restart when files change
- LiveReload support to refresh the browser automatically
- Caching disablement for templates and static resources
- Remote debugging (optional)
It is not included in production builds by default, which makes it safe to use in development.
Step-by-Step Setup
1. Add DevTools to Your pom.xml
If you’re using Maven, add this to your pom.xml
:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional> <!-- Prevents inclusion in production -->
</dependency>
</dependencies>
For Gradle:
dependencies {
implementation 'org.springframework.boot:spring-boot-devtools'
}
Make sure you’re running your app in development mode. Most IDEs like IntelliJ and Eclipse support this out-of-the-box.
2. Enable Compiler Auto-Build (IDE Specific)
IntelliJ IDEA
- Go to
Preferences
→Build, Execution, Deployment
→Compiler
- Enable “Build project automatically”
- Press
Ctrl+Shift+A
and search for Registry - Enable
compiler.automake.allow.when.app.running
Eclipse
- Enable Project → Build Automatically
- Use Spring Tools Suite (STS) for best compatibility
3. Sample Spring Boot App
DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
HelloController.java
package com.example.demo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello World!";
}
}
Try Hot Reload
- Start the Spring Boot app.
- Visit
http://localhost:8080/hello
- Change the return message in
hello()
method:
return "Hello Spring Boot DevTools!";
- Save the file. The app will restart automatically, and the change will reflect without manual intervention.
Enable LiveReload in Browser (Optional)
- DevTools includes LiveReload server on port 35729
- Install a browser extension like LiveReload Chrome Extension
- When enabled, browser refreshes automatically after frontend changes.
Template and Resource Caching
Spring Boot disables template caching when DevTools is on. For example:
# application.properties
spring.thymeleaf.cache=false
spring.freemarker.cache=false
spring.resources.cache.cachecontrol.no-store=true
This ensures your HTML/CSS/JS updates are reflected immediately.
DevTools in Production?
No! DevTools is not meant for production. It is automatically excluded if you:
- Use
spring-boot-maven-plugin
withrepackage
- Mark it as
optional
in Maven
Troubleshooting Tips
Issue | Fix |
---|---|
Hot reload not working | Ensure IDE is compiling classes on save |
Too many restarts | Only monitor src/main not target/ or logs |
LiveReload not working | Enable browser plugin and check port 35729 |
Changes not detected | Modify .class files not just comments |
Visual Diagram
You can visualize the workflow like this:
pgsqlCopyEditCode Change (Controller, Service, etc.)
↓
IDE Auto-Builds Class
↓
Spring DevTools Detects Change
↓
Automatic Restart Triggered
↓
Updated App Running Without Manual Restart
Summary
Feature | Benefit |
---|---|
Auto-restart | No manual restarts |
LiveReload | Frontend updates instantly |
No caching | Reflect template/static changes |
Dev-only | Safe for production use |
Final Thoughts
Spring Boot DevTools can drastically reduce development turnaround time. With minimal setup, you can make your application development faster, smoother, and less frustrating.