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

1 简介

为了更好的版本控制和问题定位,我们需要知道正在运行的应用是什么版本,什么时候打包的,Git的相关信息等。通过/actuator/info可以帮助我们获取这些信息。

2 配置

首先要有actuator的依赖:


  org.springframework.boot
  spring-boot-starter-actuator

然后打开对应的端口:

management:
  endpoints:
    web:
      exposure:
        include: "*"

这时就可以访问/actuator/info了,不过返回是空的。

要返回git和build的信息,我们需要增加插件:


  
    pl.project13.maven
    git-commit-id-plugin
    4.0.0
    
      
        get-the-git-infos
        
          revision
        
        initialize
      
    
    
      ${project.basedir}/.git
      true
    
  
  
    org.springframework.boot
    spring-boot-maven-plugin
    ${spring-boot-dependencies.version}
    
      
        
          build-info
        
      
    
  

这两个插件会为我们生成两个文件,一个是build-info.properties,专门放一些build的信息;另一个是git.properties,放一些版本控制的信息:

Spring Boot通过Actuator显示git和build的信息_第1张图片

当我们再访问/actuator/info时,Spring Boot就会读取并显示对应的信息了:

Spring Boot通过Actuator显示git和build的信息_第2张图片

3 总结

代码请查看:https://github.com/LarryDpk/p...

你可能感兴趣的:(java)