SpringBootDebug調(diào)試的示例分析

這篇文章給大家分享的是有關(guān)Spring Boot Debug調(diào)試的示例分析的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)公司是一家專業(yè)提供貢覺企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、網(wǎng)站設(shè)計、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為貢覺眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進行中。

最近發(fā)現(xiàn) Spring Boot 本地不能 Debug 調(diào)試了,原來 Spring Boot 升級后,對應(yīng)插件的命令參數(shù)都變了,故本文做一個升級。

背景:

Spring Boot 項目在使用 Spring Boot Maven 插件執(zhí)行啟動命令 spring-boot:run 的時候,如果設(shè)置的斷點進不去,要進行以下的設(shè)置。

官方解決方案:

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 參數(shù)

在插件 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"

Spring Boot Debug調(diào)試的示例分析

最新配置可以參考官方說明:

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

2、添加一個Remote

在開發(fā)工具里面新增一個 Remote 配置:

Spring Boot Debug調(diào)試的示例分析

只需要確定 Host、Port 參數(shù)即可。

Host:地址

localhost:本地啟動地址;

Port:端口

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

3、開始調(diào)試

先啟動加了 jvmArguments 參數(shù)的 Spring Boot 項目:

Spring Boot Debug調(diào)試的示例分析

程序停在監(jiān)聽端口:5005,再 debug 啟動Remote:

Spring Boot Debug調(diào)試的示例分析

再回到項目,開始啟動輸出日志,然后就可以進行斷點調(diào)試了。

這就是遠程調(diào)試了,也能幫你 debug 遠程 Spring Boot 應(yīng)用,但在本地調(diào)試要操作兩次,略顯麻煩。

感謝各位的閱讀!關(guān)于“Spring Boot Debug調(diào)試的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

分享名稱:SpringBootDebug調(diào)試的示例分析
網(wǎng)頁URL:http://muchs.cn/article40/ijdceo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、搜索引擎優(yōu)化、網(wǎng)站收錄云服務(wù)器、網(wǎng)站策劃網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)