1、更改idea配置
1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。
2) 组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
2、项目中导入spring-boot-devtools包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
3、application.properties配置文件添加配置项
#排除那个目录的文件不需要restart
spring.devtools.restart.exclude=static/**
spring.devtools.restart.additional-exclude=static/**,public/**
#需要开启热部署的文件目录
spring.devtools.restart.additional-paths=src/main/java
spring.devtools.restart.enabled=true
spring.devtools.add-properties=false
spring.profiles.active=dev
#禁用前端插件缓存,如thymeleaf或freemarker
spring.thymeleaf.cache=false
4、如果浏览器页面没有更新,如Chrome可禁用缓存
F12或者“Ctrl+Shift+I”,打开开发者工具,“Network” 选项卡下 选中打勾 “Disable Cache(while DevTools is open)”