Idea + SpringBoot 启动热部署支持

深碍√TFBOYSˉ_ 2024-04-17 06:07 139阅读 0赞

一、什么是热部署?

在进行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 勾选
    设置idea自动编译
  • ctrl + shift + alt + /,选择Registry,勾选compiler.automake.allow.when.app.running
    registry窗口中勾选编译器自动编译选项

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)

貌似要收费,不要钱了再考虑。

发表评论

表情:
评论列表 (有 0 条评论,139人围观)

还没有评论,来说两句吧...

相关阅读

    相关 IDEA配置支持页面部署

    > 好的热部署让开发调试事半功倍,这样的“神技能”怎么能错过呢, 使用过IDEA的童鞋赶紧进来撸一把吧。 学习目标  快速学会在项目中使用热部署插件运行项目,提高开发效