Spring Boot - Include/Exclude files to trigger restart.

[Updated: Mar 19, 2017, Created: Mar 19, 2017]

Spring provides spring. devtools. restart. exclude property to exclude files to trigger a restart. By default this property is assigned to following values:

spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resources/**,resources/**,static/**,public/**,templates/**,**/*Test.class,**/*Tests.class,git.properties

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'.

Example

src/main/resources/application.properties

spring.devtools.restart.poll-interval=10
spring.devtools.restart.quiet-period=5
spring.devtools.restart.exclude=public/myPage2.html

src/main/resources/public/myPage1.html

<html>
  <body>
    <h1>static page 1</h1>
  </body>
</html>

src/main/resources/public/myPage2.html

<html>
  <body>
    <h1>static page 2</h1>
  </body>
</html>
@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-starter-web 1.5.2.RELEASE: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
    Corresponding Spring version: 4.3.7.RELEASE
  • spring-boot-devtools 1.5.2.RELEASE: Spring Boot Developer Tools.
    Corresponding Spring version: 4.3.7.RELEASE
  • JDK 1.8
  • Maven 3.3.9

Boot Restart Exclude Example Select All Download
  • boot-restart-exclude
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
          • public

See Also