Maven和SpringBoot调试-Drun.jvmArguments = -Xdebug的真正含义

时间:2017-11-08 10:42:04

标签: java maven debugging spring-boot intellij-idea

我可以在调试模式下启动架子的主要Spring Boot应用程序我可以在IntelliJ中设置断点并且它可以工作!即在下面运行:

@SpringBootApplication
public class JasperApplication {

public static void main(String[] args) {
    SpringApplication.run(JasperApplication.class, args);
  }
}

但是如果我使用带有调试选项的maven run plugin在IntelliJ中启动我的Spring Boot应用程序:

spring-boot:run

调试不起作用。我读过关于

的文章
-Drun.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

我无法把所有东西都放在一起,有人可以让我知道它是如何运作的,或者引导我阅读一些描述整个事物的文章。

我希望能够从IntelliJ中运行maven Spring Boot插件以及命令行,能够调试和设置断点。谢谢!

1 个答案:

答案 0 :(得分:3)

当您调用spring-boot:run时,您正在启动远程进程,即此进程在IDE中运行

如果要从IDE中调试此过程,则需要满足以下先决条件:

  • 远程进程必须具有远程调试功能,这是您使用-Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

    运行该进程时所执行的操作
  • 您必须在IDE中使用远程调试器。更多细节in the docs,但简短摘要是:

    • 运行>编辑配置
    • 点击+图标,然后选择远程
    • 为运行配置命名,并为Search sources using module's classpath
    • 选择一个模块
    • 调用mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"并在IDE中启动此运行配置,两者将相互通信。

这是一个截图,显示远程运行配置如下:

enter image description here