美文网首页
SpringBoot 在IDEA中实现热部署(实用版)

SpringBoot 在IDEA中实现热部署(实用版)

作者: 中v中 | 来源:发表于2021-05-23 07:36 被阅读0次

具体步骤

一、开启IDEA的自动编译(静态)

具体步骤:打开顶部工具栏 File -> Settings -> Default Settings -> Build -> Compiler 然后勾选 Build project automatically 。

image

二、开启IDEA的自动编译(动态)

具体步骤:同时按住 Ctrl + Shift + Alt + / 然后进入Registry ,勾选自动编译并调整延时参数。

  • compiler.automake.allow.when.app.running -> 自动编译
  • compile.document.save.trigger.delay -> 自动更新文件

PS:网上极少有人提到compile.document.save.trigger.delay 它主要是针对静态文件如JS CSS的更新,将延迟时间减少后,直接按F5刷新页面就能看到效果!

image

三、开启IDEA的热部署策略(非常重要)

具体步骤:顶部菜单- >Edit Configurations->SpringBoot插件->目标项目->勾选热更新。

image

四、在项目添加热部署插件
1.pom文件中导入 spring-boot-devtools 依赖:

<!--SpringBoot热部署配置 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

2.继续在pom.xml中添加插件:

<build>
     <plugins>
     <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
                  <fork>true</fork>
                  <addResources>true</addResources>
         </configuration>
    </plugin>
     </plugins>
</build>

五、关闭浏览器缓存(重要)

打开谷歌浏览器,打开F12的Network选项栏,然后勾选【✅】Disable cache 。

image

热部署到底有多爽呢,用渣渣辉的话来说,只需体验三分钟,你就会干我一样,爱上这款呦西。

相关文章

网友评论

      本文标题:SpringBoot 在IDEA中实现热部署(实用版)

      本文链接:https://www.haomeiwen.com/subject/syeajltx.html