IDEA配置
当我们修改了Java类后,IDEA默认是不自动编译的,而spring-boot-devtools又是监测classpath下的文件发生变化才会重启应用,所以需要设置IDEA的自动编译:
(1)File-->Settings-->Compiler 勾选右侧的Build Project automatically
(2).idea 设置,快捷键 Ctrl + Alt + Shift / ,选择 Registry
然后,找到如图所示的key (Compiler autoMake allow when app running) 勾选上
(3)maven 的pom.xml 文件 添加 devtools 依赖
<!--springboot热部署--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency> (4)Springboot 的application.properties 文件中把devtools 设置为启用 #设置重启的目录 #spring.devtools.restart.additional-paths: src/main/java #classpath目录下的WEB-INF文件夹内容修改不重启 spring.devtools.restart.exclude: WEB-INF/**
配置完毕,测试一下
- 修改类–>保存:应用会重启
- 修改配置文件–>保存:应用会重启
- 修改页面–>保存:应用不会重启,但会重新加载,页面会刷新(原理是将spring.thymeleaf.cache设为false,参考:Spring Boot配置模板引擎)