Thursday, February 23, 2017

Live reload using Spring boot - Dev tools


Spring boot – Dev tools – Live reload

Spring boot dev tools provides some interesting features, this page explains how to use the live reload option.

What is live reload ?
Normally whenever you make any change in the view, you have to do the following changes.
  • Make the change in the view.
  • Restart / redeploy the application in the server.
  • Go to the browser and refresh the page.

Also the above approach works only for the web content, if it is java, you might need to rerun the build, which takes lot of time just to see a simple change.

How to implement live reload in Spring
1.       Include sprint starter for dev tools.
              <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-devtools</artifactId>
              </dependency>

2.       Create a simple controller method:

       @RequestMapping("/testlivereload")
       public String  testlivereload() {
              return "Deivee";
      
       }

3.       Install browser extensions for Live reload

4.       Enable live reload


5.       This will be connected to the server

 
6.       Now change the code and save, do not redeploy or start the server.

       @RequestMapping("/testlivereload")
       public String  testlivereload() {
              return "Spring boot - Dev tools - Live reload";
       }


The code will be autodeployed and the browser will be refreshed with the content.



If you are doing frequent changes and you dont wnat the reload to happen every now and then you change the files, you may also have a trigger file which will enable to reload only when the trigger file changes.

You can also set properties to ingnore certain folders in the project, these folders whenver modified will not trigger the reload.


You can also set the following property to disable the livereload
spring.devtools.livereload.enabled = false


No comments:

Post a Comment