Spring Boot Debug调试的示例分析

发布时间:2021-08-23 10:44:06 作者:小新
来源:亿速云 阅读:259

这篇文章给大家分享的是有关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调试的示例分析

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

https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html

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 应用,但在本地调试要操作两次,略显麻烦。

感谢各位的阅读!关于“Spring Boot Debug调试的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. Spring Cloud Gateway - 扩展
  2. Spring-boot中debug如何调试

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot debug

上一篇:mybatis xml中特殊字符如何处理

下一篇:SpringMVC/Boot如何统一异常处理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》