为 springboot 添加 debug功能

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nvd11/article/details/81267143

两种运行方式

springboot 的项目(组建)有两种方式。

  1. 直接运行java application (main class: 被@SpringBootApplication 注解那个)
  2. 运行maven 的插件 springboot:run

其中第1个能很方便地debug
但是, 跟spring 的插件thymeleaf (代替mvc)冲突.

第一种方式运行时, 会找不到项目的网页资源文件。

这里写图片描述

第二钟方法能避免呢个问题, 但系default没有提供调试功能。

解决方法

1. 在pom.xml 添加remote debug的属性

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>
                        -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
                    </jvmArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

2.在Idea(现在流行这个, 应该讲大部分网上视频用呢个ide)run - Edit configuration 的截面, 添加1个remote的item

什么也不用改,按默认就得
这里写图片描述

3. 其实配置完成, 用mvn: springboot:run 运行项目

这里写图片描述

4.在debug工具栏, 选择刚刚新建的远程debug 项目, 然后按debug按钮

这里写图片描述

小结

吴复杂, 就系要同时启动两个项目, 1个本项目, 1个远程调试…

猜你喜欢

转载自blog.csdn.net/nvd11/article/details/81267143
今日推荐