Using spring-boot-devtools in Spring Boot application

Share on:

When ever we talk about the Spring Boot then its always about the simplicity of the spring boot application.

With spring-boot-devtools the development task has become more enjoyable and productive. In this artivle we will be talking about Restart feature which come very handy with spring-boot-devtools.

Why do we need spring-boot-devtools?

Spring-boot-devtools provides two ways to restart your boot application : -

  1. Build Project - When ever you build your project spring boot take care of restart
  2. trigger-file - Restart your boot application when there is change in a file

In this article we will be focusing on both the ways to restart your boot application.

But before diving in the coding part here is the gradle dependencies which we will be needing for the spring boot.

GitHub Source Code - Clone Repo

Gradle Dependency -

 1configurations {
 2        developmentOnly
 3        runtimeClasspath {
 4            extendsFrom developmentOnly
 5        }
 6    }
 8    dependencies {
 9        compile ("org.springframework.boot:spring-boot-starter-web")
10        developmentOnly("org.springframework.boot:spring-boot-devtools")
11    }

1.Build Project - This feature of spring boot is really useful during the development when you need to start and stop your boot application many time just for testing your development changes. But with “spring-boot-devtools” you do not need to manually start and stop your application, “spring-boot-devtools” will take care of this job. Only you need to build your project and “spring-boot-devtools” will restart your application with the latest changes you have made.

To enable this feature you only need to make this dependency as “developmentOnly” in the your gradle file.

Please look at the following dependency -

1configurations {
2        developmentOnly
3        runtimeClasspath {
4            extendsFrom developmentOnly
5        }
6    }

**2.trigger-file - **Spring-boot-devtools is getting more and more developer friends when its comes to configurations. If you do not want to restart your spring boot application on each build then this feature is defently going to help you.

With the help of “trigger-file” configurations you can control the restart of your spring boot application on change of file. You can decide a java file on which you want to configure the restart feature. In application.yml or you can give a path of the java file and when ever you make a change in the file spring boot application will restart with the latest changes.

Here is an example of application.yml

 2  port: 8000
 5  devtools:
 6    restart:
 7      additional-paths:
 8        - .
 9      trigger-file:

Conclusion - I hope this little tutorial might have helped you to get better understanding on “How to use spring-boot-devtools to restart your boot application on project build time or when you make a change in a file”.
If you have any questions or queries please put your comments below and i will be happy to answer you.