1、在项目pom.xml文件中添加spring-boot-devtools依赖和启动插件。
添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
添加启动插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--如果没有fork配置,devtools不起作用,即项目修改后不会重新启动 -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
2、设置项目自动编译重启
3、设置项目编译后自动启动服务
代码中使用快捷键设置,Ctrl+Shift+Alt+/ ,出现如下界面:
选择Registry,弹出如下界面,勾选compiler.automake.allow.when.app.running
4、设置Running application update policies
Run-->Edit Configurations
5、这样整个配置就结束了。重启idea
注意:
如果你前端用的是thymeleaf,做完上面的配置后还是不能热加载,可以尝试在application.properties文件中配置spring.thymeleaf.cache=false