1.在项目中引入如下的依赖配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
加入spring-boot-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--主要是配置该项-->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
运行项目后,随意修改一处代码,发现修改后的效果,并没有呈现出来,到底是什么原因导致的呢?
2.原因是在 IDEA中默认没有开启自动编译的功能,在这里就需要我们手动进行配置即可。
File>>>Settings>>>Build,Execution,Deployment>>>Complier>>>
勾选上Build project automatically
依次点击Apply,OK即可。
3.快捷键:Shift+Ctrl+Alt+/
,在弹出的窗口中选择“1.Registry…”
4.在Registry
窗口中,找到“compiler.automake.allow.when.app.running”
,对其进行勾选,并关闭该窗口;
5.重新启动项目,运行程序并修改某行代码,你会发现热部署已生效。
****************常见devtools不能实现热部署的原因****************
- 对应的spring-boot版本。
- 是否在plugin中加入属性<fork>true</fork>。
- 编译器是否开启了自动编译的功能。
- 若设置了SpringApplication.setRegisterShutdownHook(false),则自动重启将失效。