SpringBootDebug调试过程图解
这篇⽂章主要介绍了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>
springboot原理图解...
<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"
最新配置可以参考官⽅说明:
2、添加⼀个Remote
在开发⼯具⾥⾯新增⼀个 Remote 配置:
只需要确定 Host、Port 参数即可。
Host:地址
localhost:本地启动地址;
Port:端⼝
5005:上⾯命令⾏指定的端⼝;
3、开始调试
先启动加了 jvmArguments 参数的 Spring Boot 项⽬:
程序停在监听端⼝:5005,再 debug 启动Remote:
再回到项⽬,开始启动输出⽇志,然后就可以进⾏断点调试了。
这就是远程调试了,也能帮你 debug 远程 Spring Boot 应⽤,但在本地调试要操作两次,略显⿇烦。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。