Lok*_*esh 2 java intellij-idea spring-boot
以下是我的 POM 的相关部分
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
如您所见,我已经安装了 devtools。它适用于 version 2.1.13.RELEASE
。当我在 Java 类中进行更改并在 Intellij IDEA 中点击 Build Project 时,服务器会按预期以新的更改重新启动。
但是当我将 spring boot 版本升级到2.2.0.RELEASE
或2.2.5.RELEASE
,自动重启停止工作。当我进行更改并构建项目时,没有任何反应。我检查了文档,根据该文档添加 devtools 依赖项就足够了。
文档参考:https : //docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/pdf/spring-boot-reference.pdf(第37页)
更新 1:我为任何人创建了一个演示应用程序,以尝试查看它是否适合他们。这是存储库。尝试使用mvn spring-boot:run
并在运行时编辑运行它BookApi.java
、重建,它应该会触发实时重启。
更新 2:这是我在启动应用程序时得到的日志:https : //gist.github.com/lokeshh/d111c1429323ddf6e4a8d020526ceccb
更新 3:我尝试了 STS 4 来测试问题是否出在我的 IntelliJ 上。我发现 STS 4 中也存在同样的问题。自动重新加载在保存时适用于 2.1.13,但不适用于 2.2.0。
更新 4:删除了完整的.m2
存储库,仍然是同样的问题。以下是启用了 devtools 跟踪的日志https://gist.github.com/lokeshh/d111c1429323ddf6e4a8d020526ceccb#file-output_with_trace-log
好吧,它对我也很有效,就像其他为您回答的人一样。
但我在这里为您提供解决方案。它可能会在某个时候发生。执行下面提到的步骤。
正如你已经添加的依赖在pom.xml
,所以让我们继续下一步。
下一个
确认intellij 中的设置。.
=>自动构建项目
文件 –> 设置 –> 构建、执行、部署 –> 编译器 –> check this Build project automatically
然后,检查Intellij 注册表
按SHIFT+CTRL+A
(Win/*nix) 或Command+SHIFT+A
(Mac) 打开一个弹出窗口,输入registry
查找并启用此选项 compiler.automake.allow.when.app.running
完成。现在,应该启用热插拔和静态文件自动重新加载。
如果未重新加载静态文件,请按CTRL+F9
强制重新加载。
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-devtools-restart