最近發現 Spring Boot 本地不能 Debug 調試了,原來 Spring Boot 升級後,對應插件的命令參數都變了,故本文作一個升級。html
背景:spring
Spring Boot 項目在使用 Spring Boot Maven 插件執行啓動命令 spring-boot:run
的時候,若是設置的斷點進不去,要進行如下的設置。微信
官方解決方案:app
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:
直接看怎麼作吧!jvm
在插件 spring-boot-maven-plugin
裏面加上 jvmArguments
配置。socket
<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>
或者在命令行指定:maven
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
最新配置能夠參考官方說明:spring-boot
https://docs.spring.io/spring...
在開發工具裏面新增一個 Remote 配置:工具
只須要肯定 Host、Port 參數便可。開發工具
localhost:本地啓動地址;
5005:上面命令行指定的端口;
先啓動加了 jvmArguments
參數的 Spring Boot 項目:
程序停在監聽端口:5005,再 debug 啓動Remote:
再回到項目,開始啓動輸出日誌,而後就能夠進行斷點調試了。
這就是遠程調試了,也能幫你 debug 遠程 Spring Boot 應用,但在本地調試要操做兩次,略顯麻煩。
未完,棧長將陸續分享 Spring Boot 最新技術教程,如今已經寫了一堆存貨了,關注微信公衆號 "Java技術棧" ,公衆號第一時間推送!