概述
基本概念
spring-boot-devtools: Spring Boot包括一组额外的工具,这些工具可以使应用程序开发体验更加愉快。该
spring-boot-devtools
模块可以包含在任何项目中,以提供其他开发时功能。
LiveReload:An implementation of the LiveReload server in Node.js. It's an alternative to the graphical http://livereload.com/ application, which monitors files for changes and reloads your web browser.
官方文档
spring-boot-devtools
https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#using-boot-devtools
LiveReload
https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#using-boot-devtools-livereload
http://livereload.com/extensions/
Maven
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
Gradle
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
注:
在运行完全打包的应用程序时,开发工具会自动被禁用,如果您的应用程序是从java -jar启动的,或者是从一个特殊的类加载器开始的,那么它就被认为是一个“生产应用程序”。将依赖项标记为Maven中的可选项
<optional>true</optional>
或在Gradle中使用compileOnly
是一种最佳实践,它可以防止devtools被传递到其他使用你的项目的模块中。
解决方案
spring-boot-devtools 配置过程
1、添加Maven或者Gradle依赖
2、修改IntelliJ IDEA Settings自动编译
File --> Settings --> Compiler --> Build Project automatically
3、允许APP运行时自动构建
Ctrl + Shift + Alt + / --> Registry --> 勾选Compiler autoMake allow when app running
LiveReload 配置过程
1、 spring-boot-devtools
模块包括一个嵌入式LiveReload服务器
2、从livereload.com免费获得适用于Chrome,Firefox和Safari的LiveReload浏览器扩展。
3、安装浏览器扩展
4、启用浏览器扩展
当浏览器扩展图标中间圆点空心时,热加载没有启用
点了它一下,变成黑色实心即可。
注:如果多次点击无效,说明LiveReload服务器未开启。
5、保存(Ctrl + S)文件以后,前端页面自动刷新。
注:
一次只能运行一台LiveReload服务器。在启动应用程序之前,请确保没有其他LiveReload服务器正在运行。如果从IDE启动多个应用程序,则只有第一个具有LiveReload支持。
教学资源
https://www.bilibili.com/video/av65117012/?p=25
常见问题
Spring Boot——[Unable to start LiveReload server]解决方案
参考文章
https://www.jianshu.com/p/99f17c7e12f5
https://my.oschina.net/u/3939059/blog/2252395
https://www.cnblogs.com/zcynine/p/5559794.html
最后
以上就是微笑冰棍为你收集整理的Spring Boot + IntelliJ IDEA——自动部署[Spring Boot热部署]+LiveReload[前端自动刷新、热加载]解决方案的全部内容,希望文章能够帮你解决Spring Boot + IntelliJ IDEA——自动部署[Spring Boot热部署]+LiveReload[前端自动刷新、热加载]解决方案所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复