Spring Boot Debug调试,日后必定有用!
最近发现 Spring Boot 本地不能 Debug 调试了,原来 Spring Boot 升级后,对应插件的命令参数都变了,故本文做一个升级。
背景:
Spring Boot 项目在使用 Spring Boot Maven 插件执行启动命令 spring-boot:run
的时候,如果设置的断点进不去,要进行以下的设置。
官方解决方案:
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 参数
在插件 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"
最新配置可以参考官方说明:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html
2、添加一个Remote
在开发工具里面新增一个 Remote 配置:
只需要确定 Host、Port 参数即可。
- Host:地址
localhost:本地启动地址;
- Port:端口
5005:上面命令行指定的端口;
3、开始调试
先启动加了 jvmArguments
参数的 Spring Boot 项目:
程序停在监听端口:5005,再 debug 启动Remote:
再回到项目,开始启动输出日志,然后就可以进行断点调试了。
这就是远程调试了,也能帮你 debug 远程 Spring Boot 应用,但在本地调试要操作两次,略显麻烦。
未完,栈长将陆续分享 Spring Boot 最新技术教程,现在已经写了一堆存货了,关注微信公众号 "Java技术栈" ,公众号第一时间推送!
相关文章
- 面试(4)-spring-Spring面试题和答案
- 在Spring Boot中使用内存数据库
- 附录A Spring Boot应用启动器
- Spring boot项目使用Base64加密,部署到Windows系统tomcat中遇到中文乱码问题
- Spring事务在单元测试中的应用
- 开源UReport 整合到产品中实践简要:(一)spring boot下UReport安装与配置()
- Spring boot 启动之后,执行某些初始化的几种方法
- Spring boot面试题整理
- Spring Boot整合Log4j做日志处理
- Spring Boot中使用PostgreSQL数据库
- 2015第24周二Spring事务2
- Spring Security 一键接入验证码登录和小程序登录
- 不掌握这些内置Filter 你就学不会 Spring Security
- springboot学习之七(整合spring swagger)
- Spring boot实现定时任务一:集成Quartz
- Spring之AOP
- Spring框架:Spring安全
- spring boot 2 + shiro 实现简单的身份验证例子
- 2.6 Spring事务传播
- spring quartz job
- 玩转spring boot——MVC应用
- Spring Boot @Autowired 没法自动注入的问题
- Spring Boot启动过程源码分析--转
- Auto-Publishing and Monitoring APIs With Spring Boot--转
- Spring JTA multiple resource transactions in Tomcat with Atomikos example--转载
- spring beans源码解读之--Bean的注解(annotation)
- 曹工说Spring Boot源码(4)-- 我是怎么自定义ApplicationContext,从json文件读取bean definition的?
- spring boot (4) 使用log4 打印日志
- Spring事务管理之几种方式实现事务