首页 > 其他分享 >Spring Boot通过Actuator显示git和build的信息

Spring Boot通过Actuator显示git和build的信息

时间:2023-01-12 20:22:07浏览次数:48  
标签:info git Spring boot Boot 信息 build actuator

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

标签:info,git,Spring,boot,Boot,信息,build,actuator
From: https://www.cnblogs.com/larrydpk/p/17047838.html

相关文章

  • SpringBoot-中英文页面切换(国际化)
    目录1.设置项目编码UTF82.在resources目录下新建i18n文件夹及语言配置文件3.指出国际化相关文件的位置4.展示页面5.使用按钮切换中英文页面5.1新建html页面5.2实现L......
  • Spring-循环依赖
    什么是循环依赖两个不同的实体类,却拥有有着对方对象作为属性。``Aa=newA();a.b=newB();a.c=newC();=>Bb=newB();b.a=newA()=>Cc=newC();C......
  • SpringBoot简单整合JPA
    SpringBoot简单整合JPAhttps://blog.csdn.net/qq_41378597/article/details/103444889最近帮朋友写个小项目,用惯了Mybatis,有机会想用下SpringBoot整合JPA,发现使用JPA......
  • Springboot简单整合JPA示例
    Springboot整合JPAhttps://blog.csdn.net/wdy00000/article/details/123588201文章目录JPA技术常用注解Springboot整合JPA1.引入JPA依赖2.配置3.启动类4.实体类5.......
  • springboot 自动配置 自动监控demo
    1、注解定义@Target({java.lang.annotation.ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic@interfaceUmp{publicabstractSt......
  • Spring Boot 加载外部配置文件
    SpringBoot允许你从外部加载配置,这样的话,就可以在不同的环境中使用相同的代码。支持的外部配置源包括:Java属性文件、YAML文件、环境变量、命令行参数。用@Value注解可以......
  • IDEA的Services中添加SpringBoot启动和npm启动
    1、添加SpringBoot启动点击页面最下方Services,在弹出框中点击左上角最右侧的+,在点击RunConfigurationType,在弹出框AddConfigurationType中找到SpringBoot点击......
  • 【SpringBoot】配置篇
      POM.XML<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"......
  • 形象化认识Spring Cloud相关组件
    一、整体认识Springframework架构的项目就像一栋高楼大厦,一栋大厦里租用者各色各样的公司和企业为用户提供各种各样的服务。大厦里的每间办公室都是一个容器,对应着一个dock......
  • 打开GitHub官网缓慢怎么办?
    打开GitHub官网缓慢怎么办?  1、修改hosts文件hosts文件路径:C:\Windows\System32\drivers\etc\hosts文件中添加如下内容:#github140.82.112.4github.com199.23......