美文网首页
IDEA 中SpringBoot项目配置热部署devtools

IDEA 中SpringBoot项目配置热部署devtools

作者: 想象之中丶意料之外 | 来源:发表于2022-05-27 17:37 被阅读0次

SpringBoot项目中,利用spring-boot-devtools依赖进行配置热部署

步骤

1、设置pom.xml

  • dependencies中添加 spring-boot-devtools依赖
  • build中添加spring-boot-maven-plugin插件,版本跟springboot版本要一直
<!-- dependencies中添加 spring-boot-devtools依赖 -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <!-- build中添加spring-boot-maven-plugin插件,版本跟springboot版本要一直 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.6.6</version>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

2、IDEA设置项目自动构建

  • 打开IDEA设置(File -> Settings),找到 【Build,Exection,Deployment】菜单,将下图中红色框内的全部勾选(简称ABCD项)


    Settings

3、设置maintenance

  • 先将光标聚焦到 pom.xml文件中,然后使用快捷键 Ctrl + Shift + Alt + / (windows) ,或 Shift + Alt + Command + /(mac),打开maintenance面板。

  • 点击第一个【Registry...】


    maintenance面板
  • 勾选 compiler.automake.allow.when.app.running,勾选后点击[close]保存,最后重启IDEA

    compiler.automake.allow.when.app.running

4、 重启IDEA,确保设置生效。

  • 重启idea后,先启动项目。启动后,尝试修改代码,保存。此时项目会自动重启。

注意:

  • spring-boot-devtools 不需要配置版本号,它会根据你的SpringBoot版本走。
  • spring-boot-maven-plugin 的版本号,需要选择跟你SpringBoot版本一致。
  • 最后一步,勾选 compiler.automake.allow.when.app.running 后需要重启IDEA。

说明

1、如果开启热部署后,发现idea的cpu使用率很高,建议:

  • 先确保 Idea中其他项目,Maven都能正常编译(我遇到过Idea其中有个项目Maven编译不通过,就会导致Idea一直重新自动编译该项目)
  • 还是不行,可以将idea中的其他项目从Porject中移除掉,只保留一个需要开发的项目

相关文章

网友评论

      本文标题:IDEA 中SpringBoot项目配置热部署devtools

      本文链接:https://www.haomeiwen.com/subject/zqfvprtx.html