参考文档
视频演示
警告官方
原文
The Spring Boot developer tools are not limited to local development. You can also use several features when running applications remotely. Remote support is opt-in as enabling it can be a security risk. It should only be enabled when running on a trusted network or when secured with SSL. If neither of these options is available to you, you should not use DevTools’ remote support. You should never enable support on a production deployment.
有道
Spring Boot开发工具并不局限于本地开发。在远程运行应用程序时,您还可以使用几个特性。远程支持是可选择的,因为启用它可能是一个安全风险。只有在可信网络上运行或使用SSL进行安全保护时,才应该启用它。如果这两个选项都不提供给您,您就不应该使用DevTools的远程支持。永远不要在生产部署中启用支持。
使用
图文可能不对,因为我懒得在走一遍截图了。不是很明白的看上面视频把
添加依赖这个好像可以不要
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency>
设置插件
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludeDevtools>false</excludeDevtools></configuration></plugin></plugins></build>
写点测试代码后打包放服务运行
注意:
- 如果在一台服务器上测试,要注意端口别冲突
 - 不同服务器注意防火墙
 
package io.tan.remote.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/*** 测试远程** @author tn* @version 1* @date 2021/6/10 22:06*/@RestController@RequestMapping("/remote")public class RemoteController {/*** 测试接口1* @return*/@GetMapping("1")public String function1(){return "原始接口";}}
mvn clean packagejava -jar .\RemoteSpringApplication-0.0.1-SNAPSHOT.jar --server.port=8081
测试接口是否通畅
启动本地服务进行远程新增修改的预备设置
- 修改启动类
- Use org.springframework.boot.devtools.RemoteSpringApplication as the main class.
 - Add https://myapp.cfapps.io to the Program arguments (or whatever your remote URL is).
 
 
启动本地后进行修改或者新增代码
注意启动前,线上线下代码要保持一致
package io.tan.remote.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/*** 测试远程** @author tn* @version 1* @date 2021/6/10 22:06*/@RestController@RequestMapping("/remote")public class RemoteController {/*** 测试接口1* @return*/@GetMapping("1")public String function1(){return "原始接口";}/*** 测试接口2* @return*/@GetMapping("2")public String function2(){return "测试新增一个接口";}}
远程更新代码
更新前先测试下新增的接口在远程上面是否能访问
- 使用 mvn compile 重新编译即为远程更新新的代码
 

- 测试新的接口能不能顺利访问
 



