今天就跟大家聊聊有关在Spring Boot中使用/info端点怎么实现输出Git的版本信息,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
POM配置
首先,我们可以挑选任意一个Spring Boot项目,修改它的pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
<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版本信息
运行完成后,我们可以在控台中看到类似下面的信息:
[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
配置信息:
这个文件就是当前项目的git信息,它的内容如下:
#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
,我们可以获得如下输出:
{ "git": { "commit": { "time": 1496311030000, "id": "e0540b3" }, "branch": "master" } }
其中包含了关于branch和commit的基础信息。而这个信息格式是最简模式,我们也可以通过配置下面的参数来获取更全面的git信息:
management.info.git.mode=full
重启应用后再访问/info端点,可以获得类似下面更为详细的版本信息了。
{ "git": { "build": { "host": "Lenovo-zhaiyc", "version": "1.0.0", "time": 1496311073000, "user": { "name": "didi", "email": "dyc87112@qq.com" } }, "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": "dyc87112@qq.com", "name": "didi" } }, "closest": { "tag": { "name": "chapter1", "commit": { "count": "240" } } }, "dirty": "true", "remote": { "origin": { "url": "https://git.oschina.net/didispace/SpringBoot-Learning.git" } }, "tags": "" } }
看完上述内容,你们对在Spring Boot中使用/info端点怎么实现输出Git的版本信息有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。