Work Faster in Spring Boot with DevTools
Overview
In this article, we'll cover how to improve the Spring Boot development experience by using DevTools. We'll walk through two of its most useful features: Automatic Application Restarts and LiveReload browser refresh.
Note: DevTools are disabled when running the application as a packaged JAR file in production.
Dependency
Maven
To include devtools support, simply add the module dependency to pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Setting the dependency as optional is a best practice that prevents devtools from being transitively applied to other modules using your project.
Gradle
For Gradle users, add the following to build.gradle file:
dependencies {
compile("org.springframework.boot:spring-boot-devtools")
}
Automatic Restarts
Developer Tools can restart the embedded Tomcat container whenever it detects changes to files on the classpath.
Eclipse/Spring Tool Suite IDE
No configuration necessary here. This works out of the box on Eclipse-based IDE's like Spring Tool Suite because of the default behavior for re-compiling updated files.
IntelliJ IDE
In IntelliJ, we need to toggle a few settings to make this feature work.
- Go to File > Settings > Build, Execution, Deployment > Compiler and check the "Build project automatically" box.
2. Press Ctrl+Shift+A on Windows (Shift+Command+A on Mac)
3. Type "Registry" in the search box that appears, and select the registry to open it.
4. Check the setting named compiler.automake.allow.when.app.running
5. Restart the Java application
Live Reload
Developer tools also includes a LiveReload server that can be used to automatically refresh the browser when a file has changed. Browser extensions are available at livereload.com/extensions for Chrome, Firefox, and Safari.
Below is a screenshot of the Chrome extension:
No configuration necessary here. This works out of the box on Eclipse-based IDE's like Spring Tool Suite because of the default behavior for re-compiling updated files.
what about Eclipse, does we can do the same?