SpringBoot学习历程(三):Devtools热部署

前言

  • 本人github仓库地址:https://github.com/RabbitsInTheGrass/springBoot-Learning
  • 所谓的热部署就是在你修改了后端代码后不需要手动重启,工具会帮你快速的自动重启是修改生效。其深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为restart ClassLoader,这样在有代码更改的时候,原来的restart ClassLoader 被丢弃,重新创建一个restart ClassLoader,由于需要加载的类相比较少,所以实现了较快的重启时间。

1. 引入Spring-Boot-devtools

<!-- 引入热部署依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>true</scope>
    <optional>true</optional>
</dependency>


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

devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机)。
注意:
《fork》标签的作用不太确定,有说是:避免 devtools 传递性的被应用到项目中其他的 module。

2. 热部署生效

  1. 在配置文件application.yml中添加 :
spring:
  devtools:
    restart:
      enabled: true  #设置开启热部署
  freemarker:
    cache: false    #页面不加载缓存,修改即时生效
  1. 在File >>> Settings >>> Build,Execution,Deployment >>> Compiler 中找到Build project automatically 并勾选。
    在这里插入图片描述
  2. 用Ctrl+Shift+A 快捷键打开 Registry,点击之后找到"compiler.automake.allow.when.app.running",勾选,【Close】关闭。
  3. 重启IDEA即可。

3. springboot提供的属性

---------------------------------------- 
#开发人员属性
#----- -----------------------------------
#DEVTOOLS(DevToolsProperties)
spring.devtools.add-properties = true #是否启用开发属性默认值。
spring.devtools.livereload.enabled = true #是否启用与livereload.com兼容的服务器。
spring.devtools.livereload.port = 35729 #服务器端口。
spring.devtools.restart.additional-exclude = #应当从触发完全重启中排除的其他模式。
spring.devtools.restart.additional-paths = #监视更改的其他路径。
spring.devtools.restart.enabled = true #是否启用自动重启。
spring.devtools.restart.exclude= Tests.class
spring.devtools.restart.log-condition-evaluation-delta = true #是否在重新启动时记录条件评估增量。
spring.devtools.restart.poll-interval = 1s #等待两次轮询类路径更改之间的时间。
spring.devtools.restart.quiet-period = 400ms #触发重新启动之前,无需对类路径进行任何更改所需的安静时间。
spring.devtools.restart.trigger-file =#更改后触发重新启动检查的特定文件的名称。如果未指定,则任何类路径文件更改都会触发重新启动。

#REMOTE DEVTOOLS(RemoteDevToolsProperties)
spring.devtools.remote.context-path = /~~ spring-boot!〜#用于处理远程连接的上下文路径。
spring.devtools.remote.proxy.host = #用于连接到远程应用程序的代理主机。
spring.devtools.remote.proxy.port = #用于连接到远程应用程序的代理的端口。
spring.devtools.remote.restart.enabled = true #是否启用远程重启。
spring.devtools.remote.secret = #建立连接所需的共享机密(启用远程支持所必需)。
spring.devtools.remote.secret头名= X-AUTH-TOKEN #用于传输共享密钥的HTTP标头。

4. jrebel插件

livereload ,jrebel之类的插件也可以,但是个人感觉没有devtools强大。

  • 37
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RabbitsInTheGrass

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值