Spring Boot提供了spring-boot-devtools这个模块来使应用支持热部署,可以提高开发者的开发效率,无需手动重启Spring Boot应用就能实现自动加载,之前写了一篇可以自动加载springboot静态文件的,这次的只需要在原来的基础上再加一些配置即可实现springboot工程的热部署,步骤如下:
1、pom文件增加依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork> <!--重要-->
</configuration>
</plugin>
</plugins>
</build>
2、yml文件中添加配置使其生效:
# devtools
debug: true
spring:
devtools:
restart:
enabled: true #设置开启热部署
freemarker:
cache: false #页面不加载缓存,修改即时生效
3、快捷键:Ctrl+Alt+S
4、快捷键:Ctrl+Shift+A,输入Registry,点击进入勾选: