pom.xml
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
java code
@SpringBootApplication()
public class TestApp {
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
}
application.properties
management.info.env.enabled=true
在application.properties文件里,加入下面key-value属性
[email protected]@
[email protected]@
[email protected]@
[email protected]@
[email protected]@
[email protected]@
management.info.env.enabled=true
如果您不使用starter parent,则需要在pom.xml的
src/main/resources
true
执行maven clean compile -DskipTests命令后,你会发现application.properties里定义的maven相关的占位符已经被替换了。
结果如下:
info.app.name=test_project
info.app.description=Parent pom providing dependency and plugin management for applications built with Maven
info.app.version=1.0-SNAPSHOT
info.app.encoding=UTF-8
info.app.java.source=1.8.0_321
info.app.java.target=1.8.0_321
启动spring-boot的项目,访问actuator/info节点,就可以看到下面的信息了。
{
"app" : {
"name" : "test_project",
"description" : "Parent pom providing dependency and plugin management for applications built with Maven",
"version" : "1.0-SNAPSHOT",
"encoding" : "UTF-8",
"java" : {
"source" : "1.8.0_321",
"target" : "1.8.0_321"
}
},
}
pl.project13.maven
git-commit-id-plugin
2.1.4
执行maven clean install-DskipTests 后,你会发现在你的classes目录下面有个git.properties文件生成。
git.branch=dev
git.commit.id=xxx
git.commit.user.name=xxx
......
启动spring-boot的项目,访问actuator/info节点,就可以看到下面的信息了。
{
"git" : {
"commit" : {
"time" : "2023-04-06T12:16:17Z",
"id" : "e3dd1233"
},
"branch" : "dev"
}
}
一起显示maven和git 的信息
{
"app" : {
"name" : "test_project",
"description" : "Parent pom providing dependency and plugin management for applications built with Maven",
"version" : "1.0-SNAPSHOT",
"encoding" : "UTF-8",
"java" : {
"source" : "1.8.0_321",
"target" : "1.8.0_321"
}
},
"git" : {
"commit" : {
"time" : "2023-04-06T12:16:17Z",
"id" : "e3dd1233"
},
"branch" : "dev"
}
}