Spring Boot通过Actuator显示git和build的信息
2023-03-20 15:30:53 时间
1 简介
为了更好的版本控制和问题定位,我们需要知道正在运行的应用是什么版本,什么时候打包的,Git的相关信息等。通过/actuator/info可以帮助我们获取这些信息。
2 配置
首先要有actuator的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
然后打开对应的端口:
management:
endpoints:
web:
exposure:
include: "*"
这时就可以访问/actuator/info了,不过返回是空的。
要返回git和build的信息,我们需要增加插件:
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-dependencies.version}</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
这两个插件会为我们生成两个文件,一个是build-info.properties,专门放一些build的信息;另一个是git.properties,放一些版本控制的信息:
当我们再访问/actuator/info时,Spring Boot就会读取并显示对应的信息了:
3 总结
相关文章
- ZooKeeper系列文章:ZooKeeper 源码和实践揭秘(二)
- 使用 cert-manager 为 dnspod 的域名签发免费证书
- 天天写业务代码,如何成为技术大牛?
- 老板丢给我一堆电话号码,让我挨个进行归属地、运营商查询
- 如何用excel做一份好看的年度业绩报告,让领导满意呢?
- Docker 部署服务命令
- 打造数字化软件工厂 —— 一站式 DevOps 平台全景解读
- 周杰伦《说好不哭呢》QQ音乐评论的可视化分析
- CODING 项目协同 2.0 —— 让协作有条不紊
- viewport深入理解和使用
- 太赞了!英伟达又一突破,输入关键词就可以生成直逼摄影师的大片
- 文本挖掘带你分析苏轼的一生
- 元宇宙中可跨语种交流!Meta 发布新语音模型,支持128种语言无障碍对话
- 2021-11-15:四数相加 II。给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n
- 每天重复这样的Excel操作,写个python脚本多省事!
- 你想打造属于自己的GUI图形化界面吗?看看这个文章!
- 酷炫的迁徙图和轮播图,用pyecharts也可以做出来
- 这136页PDF章章经典,没有学不会的“EXCEL数据透视表”!
- 如何使用vlookup+excel数组公式 完成逆向查找?
- 多线程 | Thread 和 Runnable 执行流程的差异