SpringBoot(十一)_springboot热部署

本文介绍如何通过配置SpringBoot的devtools实现代码修改后的自动热部署。包括在Maven依赖中添加optional属性,在plugin中配置fork属性,以及IDEA中的自动编译设置。

在开发中,后台修改了代码就要重新启动服务,很是费劲,现在我们可以让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 会自动重新加载,再也不需要我们手动点击重新部署了。

转载于:https://www.cnblogs.com/zhenghengbin/p/9255770.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值