Spring Boot DevTools
What DevTools Gives You
- Automatic restart: when a class changes on the classpath (you save/build in the IDE), the app restarts in about a second.
- LiveReload: refreshes the browser when static files or templates change (with a browser extension).
- Development defaults: disables template caching, enables more detailed web error logging.
- Automatically disabled in production: it turns itself off when running from a packaged jar with
java -jar.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>Restart in Action
Example
Change the text returned by a controller, save (VS Code) or press Ctrl+F9 / Build Project (IntelliJ):
# edit HelloController.java and saveExample output
... INFO 18244 --- [shopease] [ restartedMain] com.shopease.ShopeaseApplication : Started ShopeaseApplication in 0.612 seconds (process running for 95.31) ... INFO 18244 --- [shopease] [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
Tip: In IntelliJ, enable automatic restart on save: Settings → Build, Execution, Deployment → Compiler → Build project automatically, and Advanced Settings → Allow auto-make to start even if developed application is currently running.
Why Restart Is Fast
DevTools uses two class loaders. Library jars (Spring, Tomcat, Jackson) are loaded once in a base class loader. Your own classes are loaded in a restart class loader. On a change, only the restart class loader is thrown away and recreated, which is much faster than a cold start.
Note: A restart creates a fresh application context, so in-memory data (like a List of products added at run time) is lost. That is one reason real apps keep data in a database.