Idea + SpringBoot 启动热部署支持
一、什么是热部署?
在进行SpringBoot项目开发过程中,很多时候经常需要重启Web服务器才能保证修改的 源代码文件、或者一些诸如xml的配置文件、以及一些静态文件生效,这样耗时又低效。所谓的热部署指的是 不需要重启Web Server就可以保证各项文件修改的立即生效。下面来介绍一下在IDEA中进行SpringBoot的热部署支持。
二、使用 spring-boot-devtools
SpringBoot提供了一个名为spring-boot-devtools
的模块来使应用支持热部署,提高开发者的开发效率,无需手动重启SpringBoot应用。其原理就是spring-boot-devtools
会监听classpath下的文件变动,变动保存生效,其就会立即重启应用。
1. IntelliJ idea设置
File - Settings - Build,Excution... - Compiler - Build Project automatically
勾选ctrl + shift + alt + /
,选择Registry,勾选compiler.automake.allow.when.app.running
2. SpringBoot Project修改
在
pom.xml
中添加依赖
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-maven-plugin
true
修改
application.properties
文件,以Freemarker模板引擎为例,需要关闭freemarker页面缓存,并设置需要监听的静态文件夹关闭freemarker页面缓存
spring.freemarker.cache=false
设置刷新模板的时间间隔
spring.freemarker.settings.template_update_delay=0
设置开启热部署
spring.devtools.restart.enabled=true
spring.devtools.restart.additional-paths=src/main/resources/templates
注意:额外引入的spring-boot-devtools
依赖实际上生产环境并不需要,最好不要提交到线上。
参考:SpringBoot热部署加持
三、使用插件(JRebel)
貌似要收费,不要钱了再考虑。
还没有评论,来说两句吧...