如何在/info执行器端点获取spring boot的版本

jon*_*les 7 spring-boot spring-boot-actuator

可以通过添加在 banner.txt 中包含 Spring Boot 的版本 ${spring-boot.version}

我怎样才能对 /info 执行器端点做同样的事情。我试过同时添加

info.app.spring-boot.version=${spring-boot.version}

info.app.spring-boot.version=@spring-boot.version@

到我的应用程序属性,但没有运气。/info 端点将打印 "${spring-boot.version}" (或 "@spring-boot.version@" ),不解析占位符变量

我的下一个想法是为 spring boot 版本创建一个 maven 属性,并像这样在父部分中引用它

<properties>
    <spring.boot.version>1.5.3.RELEASE</spring.boot.version>
</properties

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>${spring.boot.version}</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为 maven 在处理部分后解析占位符变量

更新:以下确实有效,但并不理想

@Component
public class MyInfoContributor implements InfoContributor {
    @Override
    public void contribute(Info.Builder builder) {

        builder.withDetail("spring-boot.version", SpringBootVersion.getVersion());
    }
}
Run Code Online (Sandbox Code Playgroud)

bar*_*com 0

这应该有效:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <additionalProperties>
      <spring-boot-version>${spring.boot.version}</spring-boot-version>
    </additionalProperties>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

那么您就不需要 app.info 属性。