最新消息:以前的文章会整理补上,如果有时间就来坐坐吧。。。

解决Intellij 2022.2.5中Spring Boot Devtools不能热更新问题

Java 麦童 307浏览 0评论

背景

此前将个人电脑上的Intellij配置备份成了zip包,公司电脑升级以后IDEA也进行了升级,从2021升级到了2022.2.5。升级完成后写了一个SpringBoot的Demo程序,调试过程中发现Spring Boot Devtools热更新功能失效了。

IDEA版本:

IntelliJ IDEA 2022.2.5 (Ultimate Edition)
Build #IU-222.4554.10, built on March 15, 2023
Licensed to micboy
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.4.1
GC: G1 Young Generation, G1 Old Generation
Memory: 1024M
Cores: 4
Metal Rendering is ON

Kotlin: 222-1.7.10-release-334-IJ4554.10

devtools版本:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <version>2.7.14</version>
</dependency>

原因

Spring Boot Devtools会监控编译后的class路径目录,如果路径下文件发生了变化(比如重新编译),Spring Boot Devtools则会重新加载和重启Spring Boot应用。而在Intellij IDEA中,默认不会自动编译(auto build)并且默认不会更新正在运行的应用,这就导致了在Intellj IDEA中修改代码后Spring Boot应用不会重新加载新的类文件。

解决方法

IntelliJ 2021.2之后版本解决方法

1.左上角Intellj IDEA->settings->Build,Execution,Deployment->Compiler:

2.左上角Intellj IDEA->settings->Advanced Settings:

“allow auto-make to start even if developed application is currently running”前面的选择框选中并点击确认。

IntelliJ 2021.2及以前版本解决方法

1.左上角Intellj IDEA->settings->Build,Execution,Deployment->Compiler:

2.Help选项卡->Find Action->弹出对话框中搜索Registry:

3.点击Registry并找到“compiler.automake.allow.when.app.running”勾选红框中的选项:

转载请注明:麦童博客 » 解决Intellij 2022.2.5中Spring Boot Devtools不能热更新问题

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址