Spring Boot devtools - Triggering auto-restart based on a single file

[Updated: Mar 16, 2017, Created: Mar 15, 2017]

Spring Boot devtools provides an option to specify a 'trigger file'. That means, this will be the only file which will kick off the application restart if we modify it. This is good when we don't want to restart frequently on each file modification.

To use this option, we need to add the following application property:


Let's see an example how to do that.

Creating Spring boot MVC application

public class MyController1 {

  public String handle(Model model) {
      model.addAttribute("msg", "from MyController1");
      return "testView1";


<h3>Page 1</h3>
<p> ${msg} </p>
public class MyController2 {

  public String handle(Model model) {
      model.addAttribute("msg", "from MyController2");
      return "testView2";


<h3>Page 2</h3>
<p> ${msg} </p>

Let's say we want to have MyController2.java as the trigger file:


spring.mvc.view.prefix= /WEB-INF/pages/
spring.mvc.view.suffix= .jsp

The main class:

public class ExampleMain {

  public static void main(String[] args) {
      SpringApplication.run(ExampleMain.class, args);

Run the application:

 mvn spring-boot:run

Access the pages at /path1 and /path2. Modifying any file other than MyController2.java will not trigger the restart as shown in this video:

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
  • spring-boot-starter-tomcat 1.5.2.RELEASE: Starter for using Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
    Corresponding Spring version: 4.3.7.RELEASE
  • tomcat-embed-jasper 8.5.11: Core Tomcat implementation.
  • JDK 1.8
  • Maven 3.3.9

Boot Trigger File Example Select All Download
  • boot-trigger-file
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
        • webapp
          • WEB-INF
            • pages

See Also