如何通过 Maven 使用 Netbeans 调试 Spring Boot [英] How to debug Spring Boot with Netbeans via Maven
问题描述
折腾了太久,直到我在 Netbeans 8.2 和 Spring Boot 1.4.3 中获得正确的调试设置之后,我想我应该将我的发现写下来作为问答供其他人使用.
After fiddling around for way too long till I got proper debuging setup in Netbeans 8.2 with Spring Boot 1.4.3 I figured I write down my findings as Q&A for others.
问题是 Netbeans 的默认配置无法在调试模式下正确启动 Spring,当您在 Internet 上搜索时,您只能在 Spring 文档中找到无效的过时信息.
The problem is that the default configuration for Netbeans fails to properly launch Spring in debug mode and when you search the internet you only find the outdated information in the Spring docs that won't work.
如果您知道如何解决,那么解决方案很简单.请在下面找到正确的设置说明.
The solution is simple if you know how. Please find the correct setup instructions below.
推荐答案
经过测试并适用于 Netbeans 8.2 和 Spring-Boot 1.4.3:
Tested and works with Netbeans 8.2 and Spring-Boot 1.4.3:
首先确保您已包含 Spring Maven 插件(在创建新的 Netbeans Spring 项目时应已包含此插件):
First of all make sure you have the Spring Maven plugin included (this should be already included when making a new Netbeans Spring project):
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
另外,像这样包含 Spring Devtools 也是一个好主意:
Also it is a good idea to include the Spring Devtools like this:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
...
</dependencies>
现在导航到您的项目设置 -> 操作 -> 调试项目并设置以下内容:
Now navigate to your project settings -> Actions -> Debug project and set the following:
执行目标:
spring-boot:run
设置属性:
run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
现在通过常用的调试按钮运行您的应用程序,Spring 应该正确连接到 JVM 调试器.
Now run your application via the usual debug button and Spring should properly connect to the JVM debugger.
要为 Spring Boot 2.x 项目(更具体地说是 spring-boot-maven-plugin 的 2.x 版)启用 Netbeans 调试,过程完全相同,除了 run.jvmArguments
属性名称已更改为 spring-boot.run.jvmArguments
:
To enable Netbeans debugging for a Spring Boot 2.x project (and more specifically version 2.x of the spring-boot-maven-plugin) the procedure is exactly the same, except the run.jvmArguments
property name has changed to spring-boot.run.jvmArguments
:
spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
这篇关于如何通过 Maven 使用 Netbeans 调试 Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!