phpstorm xdebug本地调试断点不生效_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"

d84362cbfc5f0e61553628da6c925b9c.png

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

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

2、添加一个Remote

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

83c0615973df7397eca0e665f8912f4d.png

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

  • Host:地址

localhost:本地启动地址;

  • Port:端口

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

3、开始调试

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

579b2a1bed295984635cd8a5f654d102.png

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

78f1050d3915829b9f110ebb1682deb1.png

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

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

未完,栈长将陆续分享 Spring Boot 最新技术教程,现在已经写了一堆存货了,关注微信公众号 "Java技术栈" ,公众号第一时间推送!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值