Video in progress
What does Spring Boot DevTools give you, and should it go to production?
DevTools is a set of conveniences for working locally: it quickly restarts the application when code changes, turns off the template cache, and has LiveReload. Not for prod, only for your own machine.
📖 Answer
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
What it does:
- automatic restart: when a file on the classpath changes, the application reloads. It's fast because the libraries stay in one classloader and only your own classes are reloaded in another;
- it turns off the cache for Thymeleaf and other templates, so when you refresh the page the change shows up immediately;
- it enables more detailed logging and an error page for the web.
For restart to work in IntelliJ, the project has to be rebuilt (Build Project, or the automatic build setting).
As for production: when the application is started fully packaged with java -jar, DevTools disables itself automatically, and the Maven/Gradle plugins don't include it in the jar by default. Still, declare it optional/developmentOnly: because of the two classloaders, odd errors like ClassCastException sometimes appear, and you don't want to see them on prod.
Sign up to mark studied questions and save your progress.