由于之前一直在使用spring-boot开发,但一直苦恼于不知道如何利用debug调试代码.在网上查找了很多文章之后。学习之余决定把spring-boot项目分别在eclipse和idea的调试过程简单做一下整理,方便大家以后能根据自己的需求来学习,不足之处还望指正。其调试原理主要还是利用jvm的远程调试。有兴趣研究的可以看文章最后的链接
- **pom.xml关于jvm启动参数的配置**
- **启动spring-boot项目**
- **利用debug工具连接调试**
- **设置断点,调用api接口**
-------------------
###一、pom.xml关于jvm启动参数的配置
jvm参数配置如下所示:

简单介绍下以上参数的含义:
-Xdebug是通知JVM工作在DEBUG模式下
-Xrunjdwp是通知JVM使用(java debug wire protocol)来运行调试环境。该参数同时了一系列的调试选项
transport指定了调试数据的传送方式,dt_socket是指用SOCKET模式
server参数是指是否支持在server模式的VM中
suspend指明,是否在调试客户端建立起来后,再执行VM,如果为y,那么当前的VM就是suspend直到有debug client连接进来才开始执行程序。如果你的程序不是服务器监听模式并且很快就执行完毕的,那么可以选择在y来阻塞它的启动。
address=5005 调试服务器的端口号,客户端用来连接服务器的端口号。
###二、启动spring-boot项目
在eclipse和idea下分别启动项目。因需要不同公共环境的配置,故选择maven的启动命令:clean install -Ptest -X spring-boot:run(-Ptest表示测试环境下启动,-X表示强制执行),不依赖于任何公共配置的spring boot项目可独立执行(即启动按钮)。大家可根据自己的实际情况选择。
1.eclipse的spring -boot项目启动成功的截图如下,圈红线处表示启动成功:

2.idea的spring -boot项目启动成功的截图如下,圈红线处表示启动成功:
###三、利用debug工具连接调试
1.关于eclipse的debug连接调试,可右击项目-->选择debug as-->Debug Configuration...-->Remote Java Application-->右击new即可。
a.remote java application:

b.配置host以及port,因项目在本地启动,故使用localhost,port用之前配置的address的值,即5005端口。接着点击debug连接调试

c.debug启动连接调试成功如图所示,初始配置之后,下次可选择点击小虫子连接调试

2.关于idea的debug连接调试,可选择idea右上角的edit Configuration..(启动按钮旁)-->选择左上角的+-->选择Remote点击新增即可。
a.remote页面出现之后,同样因为spring-boot项目也是在本地启动,故使用localhost,port用之前配置的address的值,即5005端口。name名称可随意取(不作限定),接着点击ok:

b.debug启动连接调试成功如图所示,选择右边的debug启动,如图所示
①点击按钮:

②remote启动连接成功:

###四、设置断点,调用api接口
1.eclipse下编写测试类调用api接口,同时设置断点,debug调试成功(另说明,调用接口调试方法自定,不一定非要编写测试类调用)
a.编写测试类调用api接口

b.调试成功

2.idea下编写测试类调用api接口,同时设置断点,debug调试成功(另说明,调用接口调试方法自定,不一定非要编写测试类调用)
a.编写测试类调用api接口

b.调试成功

在此,关于spring-boot基于jvm分别在eclipse和idea的debug调试介绍就完成了。不足之处,还望指正。
参考文章:
http://blog.csdn.net/hongchangfirst/article/details/44191925
http://blog.csdn.net/fyq891014/article/details/7534711
http://www.cnblogs.com/krockey/p/5056945.html