pom依赖
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- 有人说optional一定要配置成true才有效, 但我调试完感觉不加optional也有效 -->
<optional>true</optional>
</dependency>
激活热部署:Ctrl+F9 或者点击小锤子(如图)
我们可以在application.properties中自定义不参与重启排除项
# 页面修改后立即生效,关闭缓存,立即刷新
spring.thymeleaf.cache=false
# 热部署生效
spring.devtools.restart.enabled=true
# 设置需要重启的目录
spring.devtools.restart.additional-paths=src/main/java
# 设置不需要重启的目录
spring.devtools.restart.exclude=static/**,public/**,WEB-INF/**
# 为 mybatis 设置,生产环境可删除
# restart.include.mapper=/mapper-[\\w-\\.]+jar
# restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
禁用热部署
禁用devtools,在application.properties文件中加入属性:spring.devtools.restart.exclude=false,或者通过编程式禁用代码如下:
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApp.class, args);
}