Skip to lesson

Spring Boot DevTools

Stopping and starting the app after every small edit wastes minutes across a day of work. A shop developer wants to change a price rule and see the result a moment later.

Automatic restart when classes change

DevTools is a development-only Spring Boot module that restarts your app automatically when its compiled classes change. You edit, build, and a second later the new code is running.

The DevTools dependency in pom.xml, then an edit, a build, and the restart in the log.

Example 1 · pom.xml: the DevTools dependency

Runs in: the boot-lab practice project (Spring Boot 4.1)

XML
<!-- pom.xml, inside <dependencies> --><dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-devtools</artifactId>    <scope>runtime</scope>    <optional>true</optional></dependency>
Sample output (trimmed with ...)
> ./mvnw spring-boot:run
...
... [  restartedMain] com.shoplite.lab.BootLabApplication      : Starting BootLabApplication using Java 21.0.7 with PID 5368 (...)
... [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
... [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
...

What this code does

  • No version: Boot manages DevTools like its starters. runtime scope keeps it out of your compile class path; optional stops it from leaking into any project that depends on yours.
  • Two signs that DevTools is active: the thread name restartedMain instead of main, and the "Devtools property defaults active!" line.
  • After editing pom.xml, reload the Maven project in the IDE (IntelliJ: the small Maven refresh button; VS Code: it asks to synchronise) and restart the app once by hand.

Example 2 · Edit, build, and watch the restart

Runs in: the boot-lab practice project (Spring Boot 4.1)

Java
// HelloController.hello() beforereturn "Hello from ShopLite";
// after the edit, then build (IntelliJ IDEA: Build → Build Project, Ctrl+F9 / Cmd+F9)return "Hello from ShopLite, now with DevTools";
Sample output (trimmed with ...)
...
2026-10-16T10:50:07.367+05:30  INFO 5368 --- [boot-lab] [  restartedMain] com.shoplite.lab.BootLabApplication      : Starting BootLabApplication using Java 21.0.7 with PID 5368 (C:\Users\asha\boot-lab\target\classes started by asha in C:\Users\asha\boot-lab)
2026-10-16T10:50:07.373+05:30  INFO 5368 --- [boot-lab] [  restartedMain] com.shoplite.lab.BootLabApplication      : No active profile set, falling back to 1 default profile: "default"
2026-10-16T10:50:07.474+05:30  INFO 5368 --- [boot-lab] [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2026-10-16T10:50:07.475+05:30  INFO 5368 --- [boot-lab] [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
...
2026-10-16T10:50:09.884+05:30  INFO 5368 --- [boot-lab] [  restartedMain] com.shoplite.lab.BootLabApplication      : Started BootLabApplication in 3.466 seconds (process running for 4.59)

(curl http://localhost:8080/api/hello  ->  Hello from ShopLite)
(edit HelloController, then build: Ctrl+F9 in IntelliJ IDEA, or ./mvnw compile)

2026-10-16T10:50:30.450+05:30  INFO 5368 --- [boot-lab] [   File Watcher] rtingClassPathChangeChangedEventListener : Restarting due to 2 class path changes (0 additions, 2 deletions, 0 modifications)
2026-10-16T10:50:30.514+05:30  INFO 5368 --- [boot-lab] [       Thread-1] o.s.boot.tomcat.GracefulShutdown         : Commencing graceful shutdown. Waiting for active requests to complete
2026-10-16T10:50:30.649+05:30  INFO 5368 --- [boot-lab] [tomcat-shutdown] o.s.boot.tomcat.GracefulShutdown         : Graceful shutdown complete
(banner again)
2026-10-16T10:50:31.092+05:30  INFO 5368 --- [boot-lab] [  restartedMain] com.shoplite.lab.BootLabApplication      : Starting BootLabApplication using Java 21.0.7 with PID 5368 (...)
...
2026-10-16T10:50:32.194+05:30  INFO 5368 --- [boot-lab] [  restartedMain] com.shoplite.lab.BootLabApplication      : Started BootLabApplication in 1.272 seconds (process running for 26.9)
2026-10-16T10:50:32.203+05:30  INFO 5368 --- [boot-lab] [  restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged

(curl http://localhost:8080/api/hello  ->  Hello from ShopLite, now with DevTools)

What this code does

  • The File Watcher saw the new class files and restarted the app inside the same JVM: the PID (5368) stays the same, and "process running for" keeps counting (26.9 seconds).
  • The first start took 3.466 seconds, the restart 1.272. Only your classes were loaded again; the libraries stayed loaded.
  • The change count comes from ./mvnw compile, which rewrites the class files; an IDE build usually reports them as modifications. "Condition evaluation unchanged" means auto-configuration made the same decisions as before.

The restart is faster than a full start because DevTools uses two class loaders (the part of the JVM that loads classes). Libraries go into a base class loader that stays; your own classes go into a restart class loader that is thrown away and rebuilt. The JVM and all jars stay warm, so only your part is loaded again.

DevTools watches the compiled output (target/classes), not your .java files. Saving a file is not enough: something has to compile it, which is the next section's job.

Restart is not hot-swap: the app context is rebuilt, so data kept in memory (an in-memory list of products, a counter in a bean) starts empty again after each restart.

Making it work in IntelliJ IDEA and VS Code

Two terminals: one runs the app, the other compiles after each edit.

Terminal
# terminal 1: run the app (DevTools active)./mvnw spring-boot:run# terminal 2: after editing, compile; terminal 1 restarts by itself./mvnw compile

Triggering a restart means getting fresh class files into target/classes while the app runs. Each IDE does it differently:

  • IntelliJ IDEA, by hand: Build → Build Project (Ctrl+F9 on Windows, Cmd+F9 on macOS) after your edits. Simple and predictable.
  • IntelliJ IDEA, automatic: Settings → Build, Execution, Deployment → Compiler → tick Build project automatically, then Settings → Advanced Settings → tick Allow auto-make to start even if developed application is currently running.
  • VS Code with the Extension Pack for Java: automatic build is on by default, so saving usually recompiles and restarts. If nothing restarts, use the terminal way.
  • Any editor: run ./mvnw compile in a second terminal while ./mvnw spring-boot:run runs in the first.

Run the app from the IDE or with spring-boot:run. Restarts only happen when the app is started from classes, not from the packaged jar.

Development-only defaults DevTools changes

Property defaults are settings DevTools switches on only while it is active, such as template caching off and full error details in responses. The log line "Devtools property defaults active!" says they are in use.

The same failing request with DevTools and in the packaged jar.

Example 3 · Error responses with and without DevTools

Runs in: the boot-lab practice project (Spring Boot 4.1)

HelloController.javaJava
// src/main/java/com/shoplite/lab/HelloController.javapackage com.shoplite.lab;
import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;
@RestControllerpublic class HelloController {
    @GetMapping("/api/hello")    public String hello() {        return "Hello from ShopLite, now with DevTools";    }
    @GetMapping("/api/stock")    public String stock() {        throw new IllegalStateException("Stock service is down");    }}
Sample output (trimmed with ...)
With DevTools (./mvnw spring-boot:run):
HTTP/1.1 500
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 16 Oct 2026 05:21:14 GMT
Connection: close

{"timestamp":"2026-10-16T05:21:13.994Z","status":500,"error":"Internal Server Error","trace":"java.lang.IllegalStateException: Stock service is down\r\n\tat com.shoplite.lab.HelloController.stock(HelloController.java:16)\r\n\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\r\n ... (about 60 more lines) ...","message":"Stock service is down","path":"/api/stock"}

Packaged jar (java -jar, no DevTools):
HTTP/1.1 500
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 16 Oct 2026 05:22:18 GMT
Connection: close

{"timestamp":"2026-10-16T05:22:18.070Z","status":500,"error":"Internal Server Error","path":"/api/stock"}

What this code does

  • Run with DevTools, the 500 response carries the exception message and the full stack trace. Handy while you build, because you see the error in curl or Postman.
  • The packaged jar has no DevTools, so the same request gets only timestamp, status, error and path. The Exception Handling module replaces this default body with ShopLite's own error format.
  • Leaking stack traces to real users tells attackers your class names and library versions: one more reason DevTools must stay out of production.

Boot 4.1.1's list includes: template and static resource caching off (spring.template.provider.cache=false, spring.web.resources.cache.period=0), so edited HTML and CSS show up at once; full error details in responses (spring.web.error.include-message, include-stacktrace and include-binding-errors set to always); and resolved exceptions logged by Spring MVC.

Every one of these is wrong for production: caching off is slow, and error details leak internals. Turn them all off in development too with spring.devtools.add-properties=false, if you want to see exactly what users will see.

Why DevTools never reaches the production jar

A grep -c on the packaged jar: how many entries mention DevTools.

Example 4 · Checking that the jar has no DevTools

Runs in: the boot-lab practice project (Spring Boot 4.1)

Terminal
./mvnw packagejar tf target/boot-lab-0.0.1-SNAPSHOT.jar | grep -c devtools
Sample output
0

What this code does

  • grep -c counts matching lines: zero entries in the jar mention DevTools, although it is in pom.xml. The Spring Boot Maven plugin leaves optional DevTools out when it repackages the jar.
  • On Windows PowerShell use jar tf target\boot-lab-0.0.1-SNAPSHOT.jar | Select-String devtools: it prints nothing. Compare Select-String tomcat, which lists the Tomcat jars.

Never in production is DevTools' main safety rule, and it is enforced twice. First, the Boot Maven plugin leaves DevTools out of the jar built by mvnw package (because it is optional). Second, even if DevTools were on the class path, it switches itself off when the app is started from a fully packaged jar with java -jar.

The <optional>true</optional> line also matters for teams: if another project depends on yours, it does not get DevTools by surprise. So the same pom.xml gives fast restarts on your laptop and a clean jar for the server, with nothing to remember at release time.

When a restart is not enough: changes to pom.xml

The base class loader holds your libraries and is built once, when the JVM starts. A DevTools restart rebuilds only your own classes, so it cannot load a new library.

After a pom.xml change: stop the app, compile, and start it again.

Terminal
# after editing pom.xml# 1. stop the running app (Ctrl+C or the IDE stop button)./mvnw compile            # downloads new jars, compiles./mvnw spring-boot:run    # full start with the new class path

So after you add or change a dependency in pom.xml, a restart cannot help: the new jar is not even downloaded yet. Stop the app, reload the Maven project in the IDE (or run ./mvnw compile), and start it again. The same goes for a new Java version or JVM options.

Also start fresh when something looks strange after many restarts, such as a bean that seems to keep old values. A full start is the honest test; DevTools is a speed-up, not a replacement.

Predict the output

Does DevTools restart?

DevTools is running. Read each change and pick what happens.

Round 1 of 2

What happens in the first terminal?

// HelloController.hello() now returns:
return "Hello from ShopLite, now with DevTools";
// then, in a second terminal: ./mvnw compile

Next step

Check your understanding

11 quick questions