• IDEA 编写 Spring Boot 项目,修改前端 html、js、css 等文件,或者后端的 java 文件后,浏览器无法实时看到修改后的内容时,此时需要设置热部署。
  • 修改 pom.xml 文件,在 pom.xml 文件 <dependencies> 中添加热部署依赖:

    <!--添加热部署-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>
  • pom.xml 文件 <plugins> 中设置插件 forktrue

    <!--热部署配置-->
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
          <!--fork:如果没有该项配置,整个devtools不会起作用-->
          <fork>true</fork>
      </configuration>
    </plugin>
  • 设置 IDEA 自动编译:File—> Settings—>Build...-> Compiler 勾选 Build Project automatically。(IDEA 旧版是 Make project automatically

  • CTRL + SHIFT + A --> 查找Registry --> 找到并勾选compiler.automake.allow.when.app.running

×