SpringBoot Debug调试

发布时间:2024-12-25 11:10

一位程序员在代码中写了个‘debug’错误,他却得意地说这是新的调试模式。 #生活乐趣# #日常生活趣事# #日常生活笑话# #工作日常笑点#

最新推荐文章于 2024-11-19 09:21:56 发布

HernSong 于 2020-01-14 08:48:02 发布

背景:

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"

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

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

2、添加一个Remote

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

只需要确定 Host、Port 参数即可。

Host:地址

localhost:本地启动地址;

Port:端口

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

3、开始调试

先启动加了 jvmArguments 参数的 Spring Boot 项目:

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

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

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

网址:SpringBoot Debug调试 https://www.yuejiaxmz.com/news/view/561797

相关内容

Springboot配置 logback日志框架,且自动清理生效
SpringBoot自定义日志配置(生产环境
Django设置 DEBUG=False后静态文件无法加载解决
Springboot健康管理系统1ii1u(程序+源码+数据库+调试部署+开发环境)
MySQL存储过程调试工具
Springboot家具商城系统h4q2o(程序+源码+数据库+调试部署+开发环境)
Springboot二手物品交易系统03374(程序+源码+数据库+调试部署+开发环境)
Springboot家庭理财分析系统nxad6(程序+源码+数据库+调试部署+开发环境)
SpringBoot在线外卖系统6x5uk(程序+源码+数据库+调试部署+开发环境)
Springboot个人健康管理系统tfg73(程序+源码+数据库+调试部署+开发环境)

随便看看