In addition to automatic restart on changes feature, the Spring Boot DevTools module also comes with an embedded LiveReload server that can be used to trigger a browser refresh whenever a resource is changed. For example, when you make some changes to a template file, the browser automatically refreshes the page uses that template – you see your changes take effect in action – no need to press F5 again and again – saving you a lot of time.

In this post, you will learn to use LiveReload with Spring Boot DevTools to significantly reduce waiting time in developing Spring Boot projects – increase your productivity.

Using LiveReload for auto-reload changes is pretty easy. Here are the steps:

  1. Add the dependency spring-boot-devtools to your project’s build file (pom.xml).
  2. Install LiveReload extension for your browser.
  3. Restart your Spring Boot application.
That’s it, and you’re all set. Enjoy better Spring Boot development experience.

 

1. Install Spring Boot DevTools

So, make sure that you have the following dependency in the Maven’s build file:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
	<scope>runtime</scope>
	<optional>true</optional>
</dependency>
If you are using Spring Tool Suite IDE, right-click on the project, then click Spring > Add DevTools. Start your Spring Boot application, and you will see LiveReload server is running by default:

LiveReload server running in console

 

2. Install LiveReload extension for your browser



Go to http://livereload.com/extensions/ and click on the link that relates to your browser. Currently, it supports Safari, Chrome and Firefox. For example, I’m using Chrome so I got this:

add livereload extension to chrome

Click Add to Chrome. and click Add extension when asked. Then you will see the LiveReload icon appears to the right of the address bar like this:

livereload on toolbar

You can click that icon to enable/disable LiveReload on a specific page in the browser. When the extension connected to LiveReload server, the small circle at the center becomes a filled dot. If not, you will see this error message:

livereload error message

 

3. What will trigger a browser refresh?

Any changes you made to a resource (Java code, HTML, properties file, etc) in the classpath will trigger a restart plus a browser refresh. In addition, changes to resources in the following directories also trigger a live reload: /META-INF/maven, /META-INF/resources, /resources, /static, /public, and /templates.


4. Disable LiveReload server

To disable LiveReload server when your Spring Boot application is running, specify the following property in the application.properties file:

spring.devtools.livereload.enabled=false

Then restart the application.

Thanks to Spring Boot DevTools that makes Spring Boot development much more convenient. 

You can also watch this video to see how to use Spring Boot DevTools in action:

 

Reference: Using Spring Boot – Developer Tools

 

Other Spring Boot Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment

   


Comments 

#2Nilson2023-08-24 12:05
Hi, dont work livereload.com/extensions/. Another recommendation?
Quote
#1Kumar2021-11-08 16:30
very useful for faster development. thanks
Quote