一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|C/C++|

服務器之家 - 編程語言 - JAVA教程 - Spring Boot中使用Actuator的/info端點輸出Git版本信息

Spring Boot中使用Actuator的/info端點輸出Git版本信息

2020-11-04 16:59翟永超 JAVA教程

這篇文章主要介紹了Spring Boot中使用Actuator的/info端點輸出Git版本信息,需要的朋友可以參考下

對于Spring BootActuator模塊相信大家已經不陌生了,尤其對于其中的/health、/metrics等強大端點已經不陌生(如您還不了解Actuator模塊,建議先閱讀《Spring Boot Actuator監控端點小結》)。但是,其中還有一個比較特殊的端點/info經常被大家所忽視,因為從最初的理解,它主要用來輸出application.properties配置文件中通過info前綴來定義的一些屬性,由于乍看之下可能想不到太多應用場景,只是被用來暴露一些應用的基本信息,而基本信息本身也可以在與Spring Cloud結合時作為服務治理的注冊信息統一管理,所以這個端點的用處并不是很大。

然而實際上,該端點除了描述應用信息之外,也還可以用來描述Git版本信息,并且整合方法非常簡單,下面我們就來看看如何使用/info端點暴露當前應用的Git版本信息。

POM配置

首先,我們可以挑選任意一個Spring Boot項目,修改它的pom.xml

  • 引入spring-boot-starter-actuator,提供/info端點
?
1
2
3
4
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • 添加git-commit-id-plugin插件,該插件用來產生git的版本信息
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<plugin>
 <groupId>pl.project13.maven</groupId>
 <artifactId>git-commit-id-plugin</artifactId>
 <version>2.1.15</version>
 <executions>
 <execution>
 <goals>
 <goal>revision</goal>
 </goals>
 </execution>
 </executions>
 <configuration>
 <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
 </configuration>
</plugin>

產生git版本信息

  • 在完成了上面的配置之后,執行git-commit-id-plugin插件

Spring Boot中使用Actuator的/info端點輸出Git版本信息

運行完成后,我們可以在控臺中看到類似下面的信息:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - dotGitDirectory E:\git_project\oschina\SpringBoot-Learning\.git
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.build.user.name didi
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.build.user.email dyc87112@qq.com
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.branch master
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - --always = true
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - --dirty = -dirty
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - --abbrev = 7
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - Tag refs [ [Ref[refs/tags/chapter1=ec8713f61cd49569886708a08adea02c8ef0a112]] ]
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - Created map: [ {} ]
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - HEAD is [ e0540b3524378de9b5d938668a0f75ec016fa5e5 ]
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - Repo is in dirty state [ true ]
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.commit.id.describe e0540b3-dirty
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.commit.id e0540b3524378de9b5d938668a0f75ec016fa5e5
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.commit.id.abbrev e0540b3
[INFO] pl.project13.maven.git.log.MavenLoggerBridge - git.dirty true
...

同時,在target/classes目錄下,我們可以發現產生了一個git.properties配置信息:

Spring Boot中使用Actuator的/info端點輸出Git版本信息

這個文件就是當前項目的git信息,它的內容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Generated by Git-Commit-Id-Plugin
#Thu Jun 01 17:57:53 CST 2017
git.build.user.email=dyc87112@qq.com
git.build.host=Lenovo-zhaiyc
git.dirty=true
git.remote.origin.url=https\://git.oschina.net/didispace/SpringBoot-Learning.git
git.closest.tag.name=chapter1
git.commit.id.describe-short=e0540b3-dirty
git.commit.user.email=dyc87112@qq.com
git.commit.time=2017-06-01T17\:57\:10+0800
git.commit.message.full=update
git.build.version=1.0.0
git.commit.message.short=update
git.commit.id.abbrev=e0540b3
git.branch=master
git.build.user.name=didi
git.closest.tag.commit.count=240
git.commit.id.describe=e0540b3-dirty
git.commit.id=e0540b3524378de9b5d938668a0f75ec016fa5e5
git.tags=
git.build.time=2017-06-01T17\:57\:53+0800
git.commit.user.name=didi

啟動測試

完成了上述配置之后,啟動應用并訪問端點,比如:curl localhost:8080/info,我們可以獲得如下輸出:

?
1
2
3
4
5
6
7
8
9
{
 "git": {
 "commit": {
 "time": 1496311030000,
 "id": "e0540b3"
 },
 "branch": "master"
 }
}

其中包含了關于branch和commit的基礎信息。而這個信息格式是最簡模式,我們也可以通過配置下面的參數來獲取更全面的git信息:

?
1
management.info.git.mode=full

重啟應用后再訪問/info端點,可以獲得類似下面更為詳細的版本信息了。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
 "git": {
 "build": {
 "host": "Lenovo-zhaiyc",
 "version": "1.0.0",
 "time": 1496311073000,
 "user": {
 "name": "didi",
 "email": "[email protected]"
 }
 },
 "branch": "master",
 "commit": {
 "message": {
 "short": "update",
 "full": "update"
 },
 "id": "e0540b3524378de9b5d938668a0f75ec016fa5e5",
 "id.describe-short": "e0540b3-dirty",
 "id.abbrev": "e0540b3",
 "id.describe": "e0540b3-dirty",
 "time": 1496311030000,
 "user": {
 "email": "[email protected]",
 "name": "didi"
 }
 },
 "closest": {
 "tag": {
 "name": "chapter1",
 "commit": {
 "count": "240"
 }
 }
 },
 "dirty": "true",
 "remote": {
 "origin": {
 "url": "https://git.oschina.net/didispace/SpringBoot-Learning.git"
 }
 },
 "tags": ""
 }
}

代碼示例:Chapter6-2-1

Github:https://github.com/dyc87112

碼云:http://git.oschina.net/didispace/SpringBoot-Learning

以上所述是小編給大家介紹的Spring Boot中使用Actuator的/info端點輸出Git版本信息,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!

原文鏈接:http://blog.didispace.com/spring-boot-actuator-info-git/?utm_source=tuicool&utm_medium=referral

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美不卡一区二区三区免 | 白丝捆绑vk | ady@ady9.映画网| 青柠网在线观看视频 | 欧亚专线欧洲m码可遇不可求 | 奇米影视在线视频8888 | 午夜五月天| 日本肉体xxxx | 日韩精选| 亚洲天堂免费看 | 窝窝色资源站 | 午夜影院在线免费观看 | 国产一区二区三区免费在线视频 | www.伊人| 性bbwbbwbbwbbw撒尿 | 精品一区二区三区高清免费观看 | 精品综合久久久久久88小说 | 国产日产欧产精品精品软件 | 欧美伊人久久久久久久久影院 | 麻豆自拍 | 亚洲第一男人天堂 | 99久久精品免费看国产四区 | 青视频在线| 国产三级精品播放 | 欧美日韩亚洲成人 | 亚洲六月丁香六月婷婷色伊人 | h杯奶水太多h | 色综合合久久天天综合绕视看 | 久久99影院 | 日韩欧美亚洲天堂 | 91麻豆国产福利在线观看 | 国产精品视频网 | 精品女同一区二区三区免费站 | 大学第一次基本都没了 | 亚洲毛片免费看 | 99热在这里只有精品 | 国产欧美久久一区二区 | 狠狠色伊人亚洲综合网站色 | 2022国产麻豆剧传媒剧情 | 成人免费播放 | 白发在线视频播放观看免费 |