1.首先關閉springBoot默認開啓的thymeleaf的緩存
在application.properties文件中添加:
#關閉默認的thymleaf:
spring.thymeleaf.cache=false
這樣,再用Update classes and resources方式更新就能更新靜態文件了.
2.修改pom.xml,在dependency那裏引入熱部署devtools的maven引用
設置如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果沒有該項配置,肯定devtools不會起作用,即應用不會restart -->
<fork>true</fork>
</configuration>
</plugin>
3.在setting裏面找到Build,Execution,Deployment->Compiler下將Build project ayutomaticaly開啓
如下圖所示;
4.Mac用戶同時按下 shitf+option+command+/ ,windows用戶的話,大概是 shift+ctrl+alt+/找到Registy,勾選compiler.automake.allow.when.app.running
如下圖示:
5.接下來在application.properties中開啓devtool:
#設置熱更新
spring.devtools.livereload.enabled=true
如果是使用的內置的tomcat啓動的項目,所有的配置到此結束,若使用我們本地的 tomcat運行的項目,需要在進行最後一個配置
如下圖所示: