zl程序教程

您现在的位置是:首页 >  后端

当前栏目

IntelliJ IDEA最新版配置SpringBoot热部署遇到的坑

SpringBootIDEA配置部署 遇到 最新版 Intellij
2023-06-13 09:11:38 时间

前言

因为最近上课一直在学SpringBoot,但是老师用的是idea2019,我是2022,于是在配置热部署的时候遇到了不少坑,下面给大家介绍一下差异点,以免入坑

pom.xml

使用SpringBoot热部署,需要在pom.xml引入dev-tool的启动器

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

然后配置插件,需要在spring-boot-maven-plugin插件中配置参数

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
                <addResources>true</addResources>
            </configuration>
        </plugin>
    </plugins>
</build>

Edit Configurations

由于2022(2021也是)版本会自动折叠配置项,搞得我找了好久才找到,在箭头指向的地方选择Modify options,选择On 'Update' action以及On frame deactivated都修改成Update classes and resources,这里很重要,考试会考的

automake

打开settings里面找到截图中的位置,File->Settings->Build,Execution,Deployment->Compiler,勾选build project automatically

敲黑板,duang duang duang

然后就是最重要的一个地方,我当时找了好久都没有找到这个地方,旧版本中需要Ctrl+Shift+Alt+/,然后选择registry,勾选compiler.automake.allow.when.app.running,但是如果能轻易找到的话,我写这篇文章干嘛,新版本的配置以及改到了settings里面,Advanced Settings,勾选Allow auto-make to start even if developed application is currently running

大功告成

这样SpringBoot就可以自动热部署了,效果还不错,但是个人感觉速度有点慢,大概得等三十多秒左右。 于是我又找到了解决办法,还是在settings里面,Languages & Frameworks->Spring->Spring Boot里面找到找到我圈起来的地方,修改的越小,热部署的速度越快,我改成1之后基本上等个两三秒就可以热部署成功了

如无特殊说明《IntelliJ IDEA最新版配置SpringBoot热部署遇到的坑》为博主MoLeft原创,转载请注明原文链接为:https://moleft.cn/post-229.html