Skip to content

Commit 918461f

Browse files
authored
Update 20.2 Automatic restart.md
1 parent ee6cc21 commit 918461f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11
###20.2 自动重启
2+
3+
如果应用使用`spring-boot-devtools`,则只要classpath下的文件有变动,它就会自动重启。这在使用IDE时非常有用,因为可以很快得到代码改变的反馈。默认情况下,classpath下任何指向文件夹的实体都会被监控,注意一些资源的修改比如静态assets,视图模板不需要重启应用。
4+
5+
**触发重启** 由于DevTools监控classpath下的资源,所以唯一触发重启的方式就是更新classpath。引起classpath更新的方式依赖于你使用的IDE,在Eclipse里,保存一个修改的文件将引起classpath更新,并触发重启。在IntelliJ IDEA中,构建工程(Build → Make Project)有同样效果。
6+
7+
**** 你也可以通过支持的构建工具(比如,Maven和Gradle)启动应用,只要开启fork功能,因为DevTools需要一个隔离的应用类加载器执行正确的操作。Gradle默认支持该行为,按照以下配置可强制Maven插件fork进程:
8+
```properties
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-maven-plugin</artifactId>
14+
<configuration>
15+
<fork>true</fork>
16+
</configuration>
17+
</plugin>
18+
</plugins>
19+
</build>
20+
```
21+
22+

0 commit comments

Comments
 (0)