SpringBoot(十一)_springboot热部署

在开发中,后台修改了代码就要重新启动服务,很是费劲,现在我们可以让SpringBoot自动编译

热启动就需要用到我们在一开始引入的另外一个组件:devtools。它是 Spring Boot 提供的一组开发工具包,其中就包含我们需要的热部署功能。但是在使用这个功能之前还需要再做一些配置。

(1)在 dependency 中添加 optional 属性,并设置为 true:

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

(2)在 plugin 中配置另外一个属性 fork,并且配置为 true:

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

(3)配置 Idea

选择 File-Settings-Compiler 勾选 Build project automatically,低版本 Idea 勾选 make project automatically。

enter image description here

使用快捷键:CTRL + SHIFT + A 输入Registry 找到选项 compile.automake.allow.when.app.running 勾选

enter image description here

全部配置完成后,Idea 就支持热部署了,大家可以试着去改动一下代码就会发现 Spring Boot 会自动重新加载,再也不需要我们手动点击重新部署了。

猜你喜欢

转载自www.cnblogs.com/zhenghengbin/p/9255770.html