当前位置: 首页 > 后端技术 > Java

SpringBoot通过Actuator显示git和build信息

时间:2023-04-02 00:14:55 Java

1简介为了更好的进行版本控制和问题定位,我们需要知道运行的应用是什么版本,什么时候打包的,以及Git的相关信息。通过/actuator/info可以帮助我们获取这些信息。2配置首先要依赖actuator:org.springframework.bootspring-boot-starter-actuator然后打开对应的端口:management:endpoints:web:exposure:include:"*"此时可以访问/actuator/info,但是返回为空。要返回git和build的信息,我们需要添加插件:pl.project13.mavengit-commit-id-plugin4.0.0get-the-git-infosrevisioninitialize${project.basedir}/.gittrueorg.springframework.bootspring-boot-maven-plugin${spring-boot-dependencies.version}<执行><执行>build-info这两个插件会为我们生成两个文件,一个是build-info.properties,专门放一些构建信息;另一个是git.properties,放一些版本控制信息:当我们再次访问/actuator/info时,SpringBoot会读取并显示相应的信息:3摘要代码请查看:https://github.com/LarryDpk/p...