热重载实现
-
配置pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency>
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 没有该配置,devtools 不生效 --> <fork>true</fork> <addResources>true</addResources> </configuration> </plugin>
-
配置idea
Build,Execution,Deploument 下 勾选Build project automatically
-
ctrl + alt + shift + /
找到registry
找到compiler.automake.allow.when.app.running 勾选
至此热重载配置完毕
说明
1、
IDEA默认的热重载时间为3秒,所以每次改完代码后需要等3秒左右项目才会重启,如果觉得太慢了可以自行修改重载时间。
在IDEA中使用快捷键 ctrl+alt+shift+/选择Registry,在Registry列表中找到 compiler.automake.postpone.when.idlw.less.thancompiler.automake.postpone.when.idlw.less.than进行修改(单位为毫秒)。
2、
IDEA的热重载并不会加载所有的类,它只会重新加载变化的类。所以重载速度会很快。