欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Spring Boot Debug调试过程图解

程序员文章站 2022-06-20 12:40:44
这篇文章主要介绍了spring boot debug调试过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 最近发现 spri...

这篇文章主要介绍了spring boot debug调试过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

最近发现 spring boot 本地不能 debug 调试了,原来 spring boot 升级后,对应插件的命令参数都变了,故本文做一个升级。

背景:

spring boot 项目在使用 spring boot maven 插件执行启动命令 spring-boot:run 的时候,如果设置的断点进不去,要进行以下的设置。

官方解决方案:

by default, the run goal runs your application in a forked process. if you need to debug it, you should add the necessary jvm arguments to enable remote debugging. the following configuration suspend the process until a debugger has joined on port 5005:

直接看怎么做吧!

1、添加 jvm 参数

在插件 spring-boot-maven-plugin 里面加上 jvmarguments 配置。

<project>
 ...
 <build>
  ...
  <plugins>
   ...
   <plugin>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-maven-plugin</artifactid>
    <version>2.2.0.release</version>
    <configuration>
     <jvmarguments>
      -xdebug -xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
     </jvmarguments>
    </configuration>
    ...
   </plugin>
   ...
  </plugins>
  ...
 </build>
 ...
</project>

或者在命令行指定:

mvn spring-boot:run -dspring-boot.run.jvmarguments="-xdebug -xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Spring Boot Debug调试过程图解

最新配置可以参考官方说明:

2、添加一个remote

在开发工具里面新增一个 remote 配置:

Spring Boot Debug调试过程图解

只需要确定 host、port 参数即可。

host:地址

localhost:本地启动地址;

port:端口

5005:上面命令行指定的端口;

3、开始调试

先启动加了 jvmarguments 参数的 spring boot 项目:

Spring Boot Debug调试过程图解

程序停在监听端口:5005,再 debug 启动remote:

Spring Boot Debug调试过程图解

再回到项目,开始启动输出日志,然后就可以进行断点调试了。

这就是远程调试了,也能帮你 debug 远程 spring boot 应用,但在本地调试要操作两次,略显麻烦。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。