第一步:新建SpringBoot项目,创建测试的Controller
package com.zhixi.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName TestController
* @Author zhangzhixi
* @Description
* @Date 2022-12-25 15:52
* @Version 1.0
*/
@RestController
@RequestMapping("/remote")
public class TestController {
@GetMapping("/debug")
public String debug() {
int integer = 0;
for (int i = 1; i <= 100; i++) {
integer += i;
}
return Integer.toString(integer);
}
}
二、IDEA新建远程JVM调试
3、将jar包上传到服务器,使用命令启动jar包
注意:
- 服务器上防火墙要开启你的项目端口(8080),和你的调试端口(5005)
java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 remote_debug-0.0.1-SNAPSHOT.jar
4、访问测试
- 1、在idea处打断点,并且启动新建的远程JVM调试服务
- 2、浏览器访问:http://43.143.195.160:8080/remote/debug
可以看到已经成功通过debug访问到了。