设为首页 加入收藏

TOP

Spring Boot通过Actuator显示git和build的信息
2023-07-25 21:41:46 】 浏览:34
Tags:Spring Boot 通过 Actuator 显示 git build

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇LeetCode 39. 组合总和 40.组合总.. 下一篇10.关于synchronized的一切,我都..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目