Spring Boot - Remote Auto Restart and LiveReload

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

Spring dev tools can also be used with remote application. Using them in production environment is not recommended, but they can be very useful in remote test or staging environments.

In this tutorial, we are going to demonstrate how to kick off auto-restart of a remote application and have a auto browser refresh with LiveReload. In the following example, we are going to deploy a Spring restful service on the remote Heroku cloud platform.

Creating a simple Spring Boot application

@RestController
public class MyController {

  @RequestMapping("/")
  public String handleRequest() {
      return "a test response";
  }
}
@SpringBootApplication
public class RemoteUpdateTestApplication {
  public static void main(String[] args) {
      SpringApplication.run(RemoteUpdateTestApplication.class, args);
  }
}

Enabling dev tools on remote server

To enable remote support for dev tools, we need to disable 'excludeDevtools' flag with spring-boot plugin configuration in pom.xml:

  <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <excludeDevtools>false</excludeDevtools>
        </configuration>
  </plugin>

src/main/resources/application.properties

spring.devtools.remote.secret=testSecret

The above property is used for authentication of remote client. Without this property remote client cannot successfully connect to the server.

The remote client

The above artifacts are necessary to run both the server application and the remote client. Remote client is run on the same code-base but with different main class: RemoteSpringApplication. This class can be invoked from the command line:

java -cp .;<app-path>;<all-necessary-jars-path> org.springframework.boot.devtools.RemoteSpringApplication http://www.example.com

Where the Java main class argument 'www.example.com" represents the remote service URL. We would usually use 'run configuration' of an IDE to run the remote client easily.

Following video shows all necessary steps and final outcome of remote restart and auto refresh.

Please check out the 'see also' section below for useful links, for example to set up heroku accounts etc.


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

Remote Update Example Select All Download
  • remote-update-app
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources

See Also