原文地址 docs.halo.run
在开发环境下,修改代码之后,每次都需要重启应用,是一个非常耗时的操作。
有一个专门解决这个问题的工具,那就是 JRebel,但是它的费用实在是太昂贵,作为普通的开发者很难承受这笔费用(但不推荐使用破解版)。
于是 Halo
最后采用了 Spring Boot
官方推荐的 Developer Tools。
这里以 IntelliJ IDEA
为例。
Settings
(Preferences on macOS)。Build, Execution, Deployment > Compiler
. 启用 Build project automatically
。应用
。Ctrl+Shift+A
(Cmd+Shift+A on macOS) 快捷键,然后搜索 Registry
。打开之后找到 compiler.automake.allow.when.app.running
,并启用它 (IntelliJ IDEA 15 and newer)。Developer Tools 原理
在保存代码的时候,IDE
会自动为我们编译代码,Developer Tools
检测到代码的 class 文件
(只能检测 classpath
下的 class 文件
)的变更,会自动重启项目。注意,这里的重启速度会有质的提升,具体原因是 Spring Boot
提供的 restart 技术
提供了两个 classloaders
:base classloader
和 restart classloader
。当项目重启的时候 restart classloader
将会被抛弃,并重启创建一个,这比 code starts
(冷启动)快很多。当然,肯定是比不上 JRebel
采用的 Reload 技术
。
更多细节请查阅: Automatic Restart