The devtools module adds tools that can make the application development easier. This includes automatically applying sensible development-time configuration for features such as caching, auto restarting after changes etc. To include devtools support, we need to add spring-boot-devtools dependency to the build file.
If you want to ensure that devtools is never included in a production build, you can use the excludeDevtools build property. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”. Developer tools are automatically disabled when running a fully packaged application.
Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change activities such as saving a file inEclipse or building the project (Build → Make Project) in Intellij.
The restart works by using two classloaders. Classes that don’t change (e.g. third-party jars) are loaded into a base classloader. Classes that you’re actively developing are loaded into a restart classloader. When the application is restarted, the restart classloader is thrown away and a new one is created.
By default, changing resources in /META-INF/maven, /META-INF/resources ,/resources ,/static ,/public or /templates will not trigger a restart but will trigger a live reload.
If you want to customize exclusions use the spring.devtools.restart.exclude property. If you want to keep defaults and add additional exclusions, use the spring.devtools.restart.additional-exclude property. To restart or reload for changes to files that are not on the classpath, use the spring.devtools.restart.additional-paths property. Use the spring.devtools.restart.exclude property to control triggering a full restart or just a live reload even here.
If you don’t want to use the restart feature you can disable it using the spring.devtools.restart.enabled property, which can be set through applications.properties or a System property before calling SpringApplication.run(…).
DevTools need an isolated application classloader to operate properly. So, when starting application via supported plugins (e.g. spring-boot-maven-plugin), forking should be enabled.
When triggering a restart, DevTools automatically ignores projects named spring-boot, spring-boot-devtools, spring-boot-autoconfigure, spring-boot-actuator, and spring-boot-starter.
For auto restart and/or reload, you could also consider reloading technologies such as JRebel from ZeroTurnaround, that work by rewriting classes as they are loaded.
The devtools module includes an embedded LiveReload server (which can be disabled) that can be used to trigger a browser refresh when resource is changed. LiveReload extensions are available for browsers.
You can only run one LiveReload server at a time, if you start multiple applications from your IDE only the first will have livereload support.