Spring Boot DevTools

Developers change code hundreds of times a day. A normal cycle stops the application, rebuilds it, and starts it again, and each cycle costs precious seconds. Spring Boot DevTools removes most of that waiting. The module restarts the application automatically after every code change and refreshes the browser on request.

DevTools targets the development machine only. Production builds leave the module out automatically.

The Auto-Save Idea

Modern writing apps save work as you type, so no one presses a save button after every sentence. DevTools brings the same comfort to Java. A developer edits a class, saves the file, and the running application reloads without a manual stop and start.

 Without DevTools                   With DevTools

 Edit code                          Edit code
   |                                  |
 Stop app                           Save file
   |                                  |
 Rebuild                            App restarts by itself
   |                                  |
 Start app                          Refresh browser
   |
 Refresh browser

Adding DevTools

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

The optional flag keeps the module away from other projects that depend on yours. Gradle users write developmentOnly 'org.springframework.boot:spring-boot-devtools'.

How Automatic Restart Works

DevTools uses two class loaders. The base loader holds libraries that rarely change, such as Spring and Hibernate. The restart loader holds your own classes. A code change throws away only the restart loader and builds a new one. Library loading is skipped, so the restart finishes much faster than a cold start.

 +------------------------------+
 |  Restart class loader        |  <-- your classes (reloaded)
 +------------------------------+
 |  Base class loader           |  <-- libraries (kept in memory)
 +------------------------------+

Triggering a Restart

DevTools watches the classpath. A restart begins when a compiled class changes, so the IDE must compile the file.

ToolHow to Trigger
Eclipse / Spring ToolsSave the file. Auto build runs by default.
IntelliJ IDEAPress Build Project, or enable automatic build while the app runs.
Command lineRun mvn spring-boot:run and compile in a second terminal.

Changes That Skip a Restart

Static files such as HTML, CSS, JavaScript, and images change without any restart. DevTools reloads those resources directly, which makes front-end tweaks quick.

LiveReload

DevTools starts a small LiveReload server on port 35729. A browser extension connects to the server and refreshes the page after each restart. The developer sees the change at once without pressing the refresh button.

Friendly Development Defaults

DevTools changes several settings that suit development.

  • Template caching turns off, so edits to Thymeleaf pages appear immediately.
  • Web logging becomes more detailed, which helps debug requests.
  • H2 console support and other helpers switch on when present.

Customizing Restart Behavior

spring.devtools.restart.enabled=true
spring.devtools.restart.exclude=static/**,public/**
spring.devtools.restart.additional-paths=src/main/extra
spring.devtools.restart.poll-interval=1s
spring.devtools.restart.quiet-period=400ms
PropertyMeaning
restart.enabledTurns automatic restart on or off
restart.excludePaths that change without a restart
restart.additional-pathsExtra folders to watch
restart.poll-intervalHow often DevTools checks for changes
restart.quiet-periodWait time after the last change before restarting

Turning Restart Off

spring.devtools.restart.enabled=false

A trigger file offers a middle path. Set spring.devtools.restart.trigger-file=.reloadtrigger, and the application restarts only when that file changes.

Global Settings

A file named .spring-boot-devtools.properties in the user home folder applies settings to every project on the machine. One setting there saves repeating the same line in each project.

Production Safety

Spring Boot treats an application as fully packaged when it runs from a jar with java -jar. DevTools disables itself in that mode. The Maven and Gradle plugins also exclude the module from the final jar. A developer never needs to remove the dependency by hand before release.

Avoid enabling remote DevTools on a live server. Remote restart opens a path that attackers could misuse.

Common Problems

  • No restart after saving: compile the project, because DevTools reacts to class files and not to source files.
  • Odd class cast errors: a library loaded by the base loader may clash with a class from the restart loader. Exclude that library from restart or turn restart off.
  • Slow restarts: large projects benefit from excluding static folders and trimming heavy startup tasks.

Best Practices

  • Keep DevTools in every development setup and out of production images.
  • Pair it with fast startup habits, such as lazy loading of rarely used beans.
  • Install the LiveReload browser extension for front-end work.
  • Restart manually after changing build files such as pom.xml.

Small time savings add up across a long project. DevTools turns the edit-and-test loop into a smooth, near-instant routine.