spring-boot-devtools在idea中热部署

发布时间 2023-05-07 10:27:13作者: 咸蛋solo粥

maven依赖

  • maven依赖文件
<dependencies>
 <!-- 热部署  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <!-- 设置为true 热部署才有效 -->
            <optional>true</optional>
        </dependency>
</dependencies>
<build>
        <plugins>
            <!-- 配置插件,让热部署依赖spring-boot-devtools生效 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 设置为true,让热部署devtools生效 -->
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 配置文件
spring:
  devtools:
    restart:
      enabled: true   # 表示启
      additional-paths: target/classes # 监听变化的目录

idea设置

image

image

image

要出现如下的样子
image

后面再修改完代码后,ctrl + F9进热部署更新