正常流程:
1、在pom.xml文件中添加devtools依赖
在pom.xml文件中的<dependencies>中添加以下代码:
<!-- 热部署devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true,依赖不会往下传递,如果有项目依赖本项目,并且想要使用devtools,需要重新引入 -->
<optional>true</optional><!--这个必须要有的-->
<version>2.0.4.RELEASE</version><!--版本号可以不写-->
<scope>true</scope><!--这个也可以不谢-->
</dependency>
2、在pom.xml文件中添加fork配置
在pom.xml文件中的<build> <plugins> <plugin>中添加以下代码:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--这下边的才是要添加的内容-->
<configuration>
<!-- 增加fork 才允许热部署 ,fork 交叉-->
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
3、设置IDEA自动编译
3.1、在File | Settings | Build, Execution, Deployment | Compiler下勾选Build project automatically。点击ok,关闭
3.2、在项目中按Ctrl + Shift + Alt + / ,选择Registry...,勾选complier.automake.allow.when...选项,最后close