Spring Boot: DevTools & Hot Reload

Spring Boot DevTools improves the development experience by automatically restarting the application when files on the classpath change, and triggering a browser refresh via LiveReload. The restart is faster than a cold start because DevTools uses two classloaders: one for stable third-party libraries and one for your application code.

Contents

Adding spring-boot-devtools

Add the snippet below to your project. No further bootstrapping is needed: Spring Boot's auto-configuration picks it up from the classpath.

XML
<!-- Maven — DevTools is automatically excluded from production JARs -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>  <!-- does not propagate to downstream modules -->
</dependency>

After adding the dependency, run the application from your IDE. DevTools activates automatically when it detects a development environment.

Automatic Restart

DevTools monitors classpath entries. When any file in target/classes (or build/classes for Gradle) changes, it restarts the application automatically.

  • In IntelliJ IDEA: enable "Build project automatically" (Settings → Build, Execution, Deployment → Compiler → Build project automatically). Also enable "Allow auto-make to start even if developed application is currently running" in Registry (Help → Find Action → Registry).
  • In Eclipse: the project is compiled automatically on every save by default.
  • From the terminal: run ./mvnw spring-boot:run and save a file. DevTools detects the change via file system polling.
The restart uses a dual-classloader strategy: the base classloader loads stable third-party JARs; the restart classloader loads your application classes. On restart, only the restart classloader is replaced, making it significantly faster than a full JVM restart.

LiveReload Browser Extension

DevTools includes an embedded LiveReload server (port 35729). When the application restarts, it sends a reload signal to connected browsers.

  • Install the LiveReload browser extension (Chrome, Firefox, Safari).
  • Click the LiveReload icon to connect to localhost:35729.
  • After a code change and restart, the browser refreshes automatically.
Properties
# Disable LiveReload if you don't need it
spring.devtools.livereload.enabled=false

Disabling Restart for Specific Paths

Some resources (e.g., static assets, templates, view files) should not trigger a restart because they do not require the application context to reload. DevTools already excludes common paths like /META-INF/resources, /resources, /static, /public, and /templates by default.

Properties
# Exclude additional paths — changes to these do NOT trigger restart
spring.devtools.restart.exclude=static/**,public/**,templates/**,custom-dir/**

# Additional paths to WATCH (paths not on classpath)
spring.devtools.restart.additional-paths=src/main/resources

# Turn off restart completely (keep LiveReload)
spring.devtools.restart.enabled=false

You can also trigger restart on demand by touching a trigger file:

Properties
# Only restart when this file changes (not on every class change)
spring.devtools.restart.trigger-file=.reloadtrigger

Remote DevTools

Remote DevTools allows you to connect to an application running in a Docker container or remote server and have it restart when you save changes locally. This is useful for developing against a remote environment.

Properties
# application.properties on the REMOTE server — enables the remote endpoint
spring.devtools.remote.secret=my-secret-key
Java
// In your IDE run configuration — run this main class pointing at the remote app
org.springframework.boot.devtools.RemoteSpringApplication
// With program argument: http://remote-server:8080
Remote DevTools opens a security-sensitive endpoint. Only enable it on trusted, non-public environments (e.g., a dev server behind a VPN). Never enable it in production. The secret must be strong and shared securely.

DevTools in Production (Auto-Excluded)

DevTools is automatically disabled and excluded from production JARs by the Spring Boot build plugins. There is no need to conditionally configure it.

  • When packaged with ./mvnw package or ./gradlew bootJar, DevTools is excluded from the JAR.
  • If you deploy an exploded JAR (e.g., via an application server), DevTools detects that it is not running from a JAR and disables itself.
  • DevTools checks for the presence of a fully packaged application and disables itself accordingly.
  • If you want to force-disable DevTools in a specific environment: set spring.devtools.restart.enabled=false in the environment's application.properties or as a system property -Dspring.devtools.restart.enabled=false.
The <optional>true</optional> in the Maven dependency prevents DevTools from being transitively included in modules that depend on your project, ensuring it is truly a development-only tool.