Milena Sapunova

Milena Sapunova


Software Developer

Enable Spring Boot Developer Tools: automatic restart on file change

Spring Boot provides additional tools to enhance the development process. As part of Spring Boot-1.3. Spring Boot Devtools module was released. To improve performance Spring Boot makes use of caches. For example compiled templates are cached to avoid parsing templates repeatedly and Spring MVC adds HTTP caching headers to responses when serving static resources. In development, however, we would like to see your changes as soon as you make them. Therefore, Spring Boot Devtools provides some very useful features, giving very fast feedback loop:

Spring Boot Devtools:

  • automatic restart whenever files on the classpath change
  • disable caching options by default
  • enable DEBUG logging for the web logging group
Automatic Restart

Spring Boot Devtools monitors the classpath resources and the only way to trigger a restart is to update the classpath. For example, in Eclipse saving a modified file causes the classpath to be updated and thus, triggers a restart. Moreover, it recompiles only the files that were changed and uses two classloaders. Classes that do not change are loaded into a base classloader, while classes that are under active development are loaded into a restart classloader. When a restart is triggered, the restart classloader is replaced by a new one. Thus, the application restart is significantly faster.

DEBUG logging

To provide more information about web requests when developing Spring MVC applications, Spring Boot Devtools will enable DEBUG logging for the web logging group. This will provide more information about requests, handlers, responses, etc.

Add Spring Boot Devtools to your project

To include Spring Boot Devtools to your project, you need to add the module dependency to your build:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>
configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}
dependencies {
    developmentOnly("org.springframework.boot:spring-boot-devtools")
}

Spring Boot Devtools & Intellij IDEA Community

If you are using Intellij IDEA, you will have to complete 2 additional steps:

Enable “Build project automatically”

Navigate to Settings (Ctrl + Alt + S)/Build, Execution, Deployment/Compiler and select Build project automatically: intellij compiler build project automatically

Change Registry settings:

Go to Registry by pressing Ctrl + Shift + A and search for Registry. In the registry find (you can filter the list by typing):

compiler.automake.allow.when.app.running

intellij registry automake when app running