Spring Boot Hot Swap with Intellij IDEA

Spring Boot 热部署

Spring Boot Application Live Reload (Hot Swap) With Intellij IDEA

Spring Boot 101 (Part 8) - Live Reload / Hot Swap | YouTube

springboot idea 热部署配置

  1. 添加 devtool 依赖

    1
    2
    3
    4
    5
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    </dependency>

    注意:还需要添加 maven 插件,否则无效

    1
    2
    3
    4
    5
    6
    7
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <fork>true</fork>
    </configuration>
    </plugin>
  2. IDEA 开启自动编译

    Settings –> Build, Execution, Deployment –> Compiler –> Build project automatically

  3. IDEA 开启 automake 功能

    CTRL + SHIFT + ALT + / –> Registry –> compiler.automake.allow.when.app.running

    注意:调整触发热部署的延迟时间

    compiler.automake.trigger.delay

    compiler.document.save.trigger.delay

  4. IDEA 配置更新时触发事件

    Edit Configuration –> On ‘Update’ action –> Update classes and resources

    注意:官方不推荐设置在失焦(On frame deactivation)的时候更新