Spring provides spring. devtools. restart. exclude property to exclude files to trigger a restart. By default this property is assigned to following values:
It's always a good idea to check these properties in Spring boot's Dev Tools Properties . java as the values might change from version to version.
By default static/public files are also excluded to trigger a restart.
Note that, the excluded files do not trigger a restart but they might still get updated on the browser by LiveReload.
In this tutorial we will also use the following restart delay properties (which got nothing to do with above property):
spring.devtools.restart.poll-interval=1000 #Amount of time (in milliseconds) to wait between polling for classpath changes.
spring.devtools.restart.quiet-period=400 #Amount of quiet time (in milliseconds) required without any classpath changes before a restart is triggered.
The values shown are the default ones. By using smaller values, we can reduce restart delay. Also 'quiet-period' must be exclusively less than 'poll-interval'.
@SpringBootApplication
public class ExampleMain extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) {
return builder.sources(ExampleMain.class);
}
public static void main(String[] arg) {
SpringApplication.run(ExampleMain.class, arg);
}
}
Run the application
mvn spring-boot:run
Output
Following video first shows the behavior when default value of spring. devtools. restart . exclude is used, and then overrides this property with 'public/myPage2.html'.
Excluding additional paths
If we don't want to override the default value of spring. devtools. restart. exclude, then we can use following property to exclude additional paths:
spring.devtools.restart.additional-exclude
By default no value is assigned to this property.
Example Project
Dependencies and Technologies Used:
Spring Boot 1.5.2.RELEASE Corresponding Spring Version 4.3.7.RELEASE
spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container.
spring-boot-devtools : Spring Boot Developer Tools.