spring boot配置devtools热启动

 如果是父子模块,可以把下面的配置添加到父模块的pom.xml

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

 

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork><!-- 如果没有该配置,热部署的devtools不生效 -->
                </configuration>
            </plugin>
        </plugins>
    </build>

 

   如果是Eclipse,配置到这里,只要重启服务,热部署就会生效了。

    但是IDEA的话,热部署还不会生效,因为devTools只会在类路径上的文件发生更改时才会自动重启,而IDEA默认不会自动编译。

    解决方法有两种:

    1、手动:修改完代码,按快捷键Ctrl+F9,手动构建项目,或者只修改单个类文件的话,按Ctrl+Shift+F9,重新编译该类文件,即可触发重启服务。

    2、自动:

        1)File -> Settings -> Compiler,勾选 Build Project automatically

         2)按快捷键Ctrl+Shift+Alt+/,选择1.Registry...

         3)勾选 compiler.automake.allow.when.app.running 即可

posted @ 2022-05-03 19:26  jamstack  阅读(103)  评论(0编辑  收藏  举报