第三章 Springboot 热部署
发布日期:2021-06-30 12:36:44
浏览次数:5
分类:技术文章
本文共 3382 字,大约阅读时间需要 11 分钟。
目录
1 原理
平常开发项目时,修改了Java代码或者配置文件之后,需要手动重启项目才能生效。所谓的热部署就是在修改了后端代码之后不需要手动重启,工具会帮你快速的自动重启使修改生效。
pring-boot-devtools模块能够实现热部署。深层原理是使用了两个ClassLoader
,一个Classloader加载那些不会改变的类(第三方Jar包)
,另一个ClassLoader加载会更改的类,称为restart ClassLoader
。这样在有代码更改的时候,原来的restart ClassLoader被丢弃,重新创建一个restart ClassLoader,由于需要加载的类相比较少,所以实现了较快的重启时间。
devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),因其采用的虚拟机机制,所以重启是很快的。
2 演示环境
- IDEA 2019
- Spring Boot Maven项目
3 操作步骤
3.1 在pom.xml文件中添加依赖
org.springframework.boot spring-boot-devtools runtime true
org.springframework.boot spring-boot-maven-plugin true true
完整pm.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.3.RELEASE com.nobody springboot-devtools 0.0.1-SNAPSHOT springboot-devtools Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin true true
3.2 IDEA设置
使用ctrl+shift+a
快捷键搜索Registry,选择搜索出来的第一个,找到compiler.automake.allow.when.app.running
,勾上开启此功能。
4 配置文件说明
如果我们想对热部署进行一些设置,可以在application.properties文件(或者application.yml)添加一些属性变量来修改。
server.port=8081#主要配置#是否启用自动重启功能spring.devtools.restart.enabled=true#重启服务的文件夹目录spring.devtools.restart.additional-paths=src/main/java#不重启服务的文件夹配置spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resouces/**,resources/**, static/**,public/**,templates/**,**/*Test.class,**/*Tests.class,git.properties#非主要配置#是否启用一个livereload.com兼容的服务器#spring.devtools.livereload.enabled=true#端口livereload.com服务器端口#spring.devtools.livereload.port=35729#在原理来的基础上新增不重启服务的文件夹目录#spring.devtools.restart.additional-exclude=#设置对路径变化进行监测的时间间隔(以毫秒为单位)#spring.devtools.restart.poll-interval=1000#在没有改变任何classpath的情况下,在重启被触发前的静默时长(以毫秒为单位)#spring.devtools.restart.quiet-period=400#设置触发条件,当需要实际触发重启检查时,则需要修改这个文件#spring.devtools.restart.trigger-file=
5 项目下载地址
转载地址:https://javalib.blog.csdn.net/article/details/105753453 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月22日 19时40分56秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
史上最烂项目:苦撑12年,600多万行代码...
2019-05-01
斯坦福后空翻机器人设计、代码全开源,成本降至3000美元,人人皆可DIY
2019-05-01
请停止学习框架
2019-05-01
考研比惨五大专业排行榜,第一名没人不服!
2019-05-01
没钱没公司,怎么做一款付费产品
2019-05-01
Python 3.8 新特性来袭
2019-05-01
查询亿级数据毫秒级返回!Elasticsearch 是如何做到的?
2019-05-01
FastAPI 构建 API 服务,究竟有多快?
2019-05-01
为什么Quora选择用Python语言?
2019-05-01
一劳永逸学编程的方法
2019-05-01
代码整洁之道-编写 Pythonic 代码
2019-05-01
100行python代码,轻松完成贪吃蛇小游戏
2019-05-01
如何科学的刷 Leetcode
2019-05-01
树莓派程序开机自启动
2019-05-01
WiFi强力信号连接方案
2019-05-01
连锁门店无线通信方案
2019-05-01
ATM终端无线方案
2019-05-01
配置Lotus Domino集群视频详解
2019-05-01
通过PXE安装Linux实况
2019-05-01