【SpringBoot】——SpringBoot热部署无效的问题

首先在pom.xml中添加一个依赖

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

然后修改 idea 设置,setting — compiler,将 Build project automatically 勾选上:设置项目自动生成
ctrl + Shift + a 输入 registry 或者 ctrl + Alt + Shift + /,选中 Registry…,将 compiler.automake.allow.when.app.running 勾上:


在这里插入图片描述
到这里就差不多,测试一下,如果还是不行的话,就在 pom.xml 中添加:

<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>

每次修改完代码,都 ctrl + s 保存一下,虽然 idea 有自动保存的功能,但有时,不手动 ctrl + s 可能不会热部署。