SpringBoot热部署
开启IDEA的自动编译(动态)
具体步骤:同时按住 Ctrl + Shift + Alt + / 然后进入Registry ,勾选自动编译并调整延时参数。
- compiler.automake.allow.when.app.running -> 自动编译
- compiler.document.save.enabled -> 自动更新文件
- compile.document.save.trigger.delay -> 自动更新文件延时
PS:compile.document.save.trigger.delay 它主要是针对静态文件如JS CSS的更新,将延迟时间减少后,免编译直接按F5刷新页面就能看到效果!
-
Ctrl + Shift + Alt + /
-
进入Registry
开启IDEA的热部署策略(非常重要)
具体步骤:顶部菜单- >Edit Configurations->SpringBoot插件->目标项目->勾选热更新。
devtools依赖方式
我们在使用idea运行springboot项目时想要实现热部署,首先需要添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
到此我们尝试运行项目,看看热部署是否生效。如果还是不生效不要着急,可以在pom文件里增加fork为true
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<fork>true</fork><!-- 如果没有该配置,热部署的devtools不生效 -->
</configuration>
</plugin>
</plugins>
</build>
使用热部署
手动编译
修改代码后点击编译按钮(绿锤子)即可
自动编译(不推荐,白白消耗性能)
首先在File–>settings找到compiler,勾选自动编译