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 總結
代碼請查看:https://github.com/LarryDpk/pkslow-samples
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/541804.html
標籤:Java
