1.引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true, 依赖不会传递, 该项目依赖devtools;
之后依赖boot项目的项目如果想要使用devtools, 需要重新引入 -->
<optional>true</optional>
</dependency>
2.配置文件
spring:
datasource:
name: test
url: jdbc:mysql://127.0.0.1:3306/cdn
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
#开启或者关闭freemarker和thymeleaf的页面缓存
freemarker:
cache: false
thymeleaf:
cache: true
devtools:
remote:
restart:
enabled: true
#需要开启热部署的文件目录
restart:
additional-paths: src/main/java
#使用了mybatis好像需要设置,应该没有必要。且生产环境需要移除
#restart.include.mapper=/mapper-[\\w-\\.]+jar
#restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
#静态文件下不需要重启
#spring.devtools.restart.exclude=static/**,public/**
#spring.devtools.restart.exclude=WEB-INF/**
3.更改idea配置
1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。
2) 组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
4.Chrome禁用缓存(如果还是无法使用)
F12或者“Ctrl+Shift+I”,打开开发者工具,“Network” 选项卡下 选中打勾 “Disable Cache(while DevTools is open)”