How it works...

It might look like voodoo magic, but the science behind the Remote Restart functionality is pretty straightforward. Under the hood, when a DevTools module is included, the HTTP endpoint handler for /.~~spring-boot!~/restart automatically gets added. This allows the RemoteSpringApplication process to send the code change payload via an HTTP tunnel to the remote application and back.

To make sure that no malicious outside debug connection gets to connect to our remote application, the value of the spring.devtools.remote.secret property gets sent across and verified to establish the authenticity of the request.

In step 2 of the recipe, we launched the RemoteSpringApplication process with a program arguments value of http://127.0.0.1:8080, which is how RemoteSpringApplication knows how to communicate with our remote application. The RemoteSpringApplication class itself scans for the local file changes from an IDE by monitoring the classpath.

In step 6 of the recipe, when we added the property to our config in the code, it is very important to note that we made the change to the application.properties file located in the running classpath of the RemoteSpringApplication class not under src/main/resources, but under the build/resources/main directory, where Gradle has placed all the compiled files—hopefully that's the same directory your IDE is using as a classpath to run RemoteSpringApplication. If that's not the path your IDE is using, you should make the change in the appropriate folder, where the IDE has compiled the classes—for IntelliJ IDEA that would be the out/production/resources directory by default.

If DevTools needs to be enabled inside an application running as a Docker container, we need to explicitly configure the build script to do so by adding the following to the build.gradle file in the main project:

bootJar { 
    ... 
    excludeDevtools = false 
} 

The reason we need to do this is because, by default, when a Spring Boot application gets re-packaged for production deployment, which is the case when building a Docker container image, the DevTools module is excluded from the classpath during build time. To prevent this from happening, we need to tell the build system to not exclude the module in order to take advantage of its capabilities, namely the Remote Restart.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.212.99