Use Actuator's/info endpoint to output git version information in Spring boot

Source: Internet
Author: User
Tags spring boot actuator lenovo

For Spring Boot Actuator module Believe everyone is no stranger, especially for the/health,/metrics and other strong big-endian point is not unfamiliar (if you do not understand the actuator module, it is recommended to read the Spring Boot Actuator Monitoring Endpoint Summary). However, one of the more special endpoint/info is often overlooked, because from the initial understanding, It is mainly used to output some of the attributes defined by the info prefix in the application.properties configuration file, and because it may not be possible to imagine too many scenarios at first glance, it is used to expose basic information about some applications, and the basic information itself can be When Cloud is combined as a service governance registration information is unified management, so this endpoint is not very useful.

In practice, however, this endpoint can also be used to describe Git version information in addition to the application information, and the integration method is simple, so let's look at how to use the/info endpoint to expose Git version information for the current app.

POM Configuration

First, we can pick any one of the spring boot projects and modify its pom.xml. Introduce Spring-boot-starter-actuator to provide/info endpoints:

<dependency>

<groupid>org.springframework.boot</groupid>

<artifactid>spring-boot-starter-actuator</artifactid>

</dependency>

Add the Git-commit-id-plugin plug-in that is used to generate GIT version information:

<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>

Generate Git version information

After you have completed the above configuration, execute the Git-commit-id-plugin plugin.

After the run is complete, we can see information similar to the following in the console:

[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 [email protected]

[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

...

At the same time, in the Target/classes directory, we can find that a git.properties configuration information has been generated.

This file is the GIT information for the current project, which reads as follows:

#Generated by Git-commit-id-plugin

#Thu June 17:57:53 CST 2017

[Email protected]

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

[Email protected]

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

Start test

Once the above configuration has been completed, launch the application and access the endpoint, for example: Curl Localhost:8080/info, we can get the following output:

{

"Git": {

"Commit": {

"Time": 1496311030000,

"id": "e0540b3"

},

"Branch": "Master"

}

}

It contains basic information about branch and commit. This information format is the simplest mode, and we can also get more comprehensive git information by configuring the following parameters:

Management.info.git.mode=full

After restarting the app and then accessing the/info endpoint, you can get more detailed version information like the following.

{

"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": ""

}

}

Use Actuator's/info endpoint to output git version information in Spring boot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.