1、添加开发辅助工具包;maven配置文件添加以下依赖(如出现找不到类问题,是jar包兼容性问题,可设置适合的版本号)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
2、关闭热部署自动重启功能;在springboot的配置文件中配置以下参数,
在properties中配置如下:
spring.devtools.restart.enabled=false
或在yml中配置如下:
spring:
devtools:
restart:
enabled=false
3、设置idea允许自动编译,即使开发应用程序当前正在运行;
idea-2021-2以后的版本:
在File-Settings-Advanced Settings中配置,勾选Compiler的Allow auto-make to start even if developed application is currently running配置
老版本:
按快捷键ctl + shift + alt + /,选中registry,勾选compiler.automake.allow.when.app.running配置
4、测试验证,debug项目后,在修改、重新编译代码后,idea的Debug窗口出现绿色提示(1 class reloaded...),说明已经成功;
出现红色提示,配置失败或者修改的代码不支持热替换(新增方法、新增成员变量、新增类都不支持,只支持方法内的修改),需重启项目
5、建议:将idea的自动编译功能关闭,手动编译能更好控制修改内容,配置如下:
在File-Settings-Build,Execution,Deployment中,去掉Build project automatically配置
ideaSpringBoot项目设置HotSwap
最新推荐文章于 2024-06-21 09:24:13 发布