在工作经常遇到连接开发数据库,程序没有问题,但一到线上或者测试环境运行就出现各种问题,现在我们来配置远程debug。
一、原理
本机和远程主机的两个 VM 之间使用 Debug 协议通过 Socket 通信,传递调试指令和调试信息。
被调试程序的远程虚拟机:作为 Debug 服务端,监听 Debug 调试指令。jdwp是Java Debug Wire Protocol的缩写。
调试程序的本地虚拟机:IDEA 中配置的 Remote Server,指定 Debug 服务器的Host:Port,以供 Debug 客户端程序连接。
二、远程调试步骤
1、利用spring-boot创建测试项目ares-boot,并编写测试Controller
package com.ares.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloController {
@RequestMapping("")
public String hello(String name) {
return "hello " + name;
}
}
打成jar包,利用java -jar 启动服务
java -agent