在 Spring Boot 应用程序中,如果您对代码进行更改,是否可以在不重新启动服务器的情况下看到它们?如果是的话,如何实现?
将 spring-boot-devtools 模块添加到您的项目中,其中包括 LiveReload 服务器,可用于在资源更改时触发浏览器刷新。您可以从 livereload.com 下载浏览器扩展。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
您只需要在
devtool
和 yml 文件属性中添加 pom.xml
依赖即可:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
# for not restarting the server every time
spring.devtools.restart.enabled: false
我正在使用intellij,以下依赖设置对我有用。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
尝试以下步骤,应该可以工作
将以下内容添加到pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
在application.properties中
spring.devtools.restart.enabled=true
注意:更改 application.properties 文件后,确保 spring boot 重新启动一次。
欲了解更多信息,请查看 https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-devtools.html
如果您的 pom.xml 中有依赖项,只需在 STS 的“项目”选项卡中启用“自动构建”即可