步骤
- 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> 不能被其它模块继承,如果多个子模块可以去掉 不必须
<scope>runtime</scope> 只在运行时起作用 打包时不打进去
</dependency>
- 添加plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart 这个要手动加进去 -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
- 打开IDEA的开启运行时编译
a. 设置File ->Setting ->Compile: 勾选“Make project automatically”选项

b. 使用快捷键ctrl+alt+shift+/,选择选项Registry,打开下面的界面 并找到图中红框的选项"compller.automake.allow.when.app.running"并勾选.
