转自Monster_起飞:https://blog.csdn.net/Monsterof/article/details/108195155?spm=1001.2014.3001.5501
SpringBoot项目实现热部署方法
最近在小编在开发中用到了热部署,在这里做如下记录:
一、什么是热部署?
所谓热部署,就是在应用正在运行的时候升级软件,却不需要重新启动应用。
二、什么是SpringBoot热部署?
通俗的说,就是当你在修改SpringBoot项目中的静态资源的时候,不需要每一次都要去重启项目才能达到预期效果。
三、怎么使用SpringBoot热部署?
1.pom文件中导入spring-boot-devtools依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- servlet依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!--SpringBoot热部署配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
<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>
2.设置application.properties配置文件
#配置项目热部署
spring.devtools.restart.enabled=true
3.在Settings…中设置自动编译
首先ctrl+alt+s打开设置,在Settings…中搜索Compliler,勾选Build project automatically,如下图所示:
4.快捷键Ctrl + Shift + Alt + /,出现如下图所示界面,点击Registry…,如下图:
点击进入后,勾选compiler.automake.allow.when.app.running后Close即可
以上步骤,就完成了SpringBoot项目的热部署功能!