目的:修改类文件可以马上编译发布,提高了工作效率
步骤:
第一步:
修改pom.xml
<!-- 热启动 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional>
</dependency>
有些博客没有写下面的配置,不写不会生效的,亲测。
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><fork>true</fork></configuration></plugin></plugins>
</build>
第二步:
开启自动编译
只要classpath下的文件有变动,它就会自动重启。这在使用IDE时非常有用,因为可以很快得到代码改变的反馈。默认情况下,classpath下任何指向文件夹的实体都会被监控,注意一些资源的修改比如静态assets,视图模板不需要重启应用。
由于DevTools监控classpath下的资源,所以唯一触发重启的方式就是更新classpath。在Eclipse里,保存一个修改的文件将引起classpath更新,并触发重启。在IntelliJ IDEA中,默认是不自动编译的,我们需要设置自动编译。
Eclipse
project->Build Automatically

IDEAfile->settings->build,execution,deployment -> compile

快捷键Ctrl + Shift + Alt + /,选择Registry


重启应用,当改动代码时,观察控制台输出,你会发现Spring Boot已经检测到了文件变化,并重新启动。恭喜你~
特别的
IDEA有收费的插件:JRebel for IntelliJ
激活相关:https://blog.csdn.net/xingbaozhen1210/article/details/81093041
添加GIT忽略
![]()
*rebel.xml*
*rebel-remote.xml*



















