How to get the version of Spring Boot in the /info actuator endpoint
Asked Answered
D

3

11

It's possible to include the version of Spring Boot in the banner.txt by adding ${spring-boot.version}.

How can I do the same for the /info actuator endpoint? I've tried adding both of the following to my application properties, but no luck:

The /info endpoint will print "${spring-boot.version}" (or "@spring-boot.version@" ), doesn't resolve the placeholder variable

My next idea was to create a Maven property for the Spring Boot version and reference it in the parent section like so

<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>

But this didn't work because Maven resolves placeholder variables AFTER handling the <parent> section

UPDATE

The following does work, but it's not ideal:

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

        builder.withDetail("spring-boot.version", SpringBootVersion.getVersion());
    }
}
Diamagnetic answered 21/4, 2017 at 14:6 Comment(1)
Why isn't your updated solution not ideal? It returns exactly what you want... Else configure maven to process your properties file to replace the @prop@. However I would probably go for the InfoContributor.Urethroscope
G
0

This should work:

<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>

You then don't need the app.info properties.

Guest answered 21/8, 2017 at 20:7 Comment(0)
S
0

As you mentioned in your update, an InfoContributor can be used to add this property based on the value in SpringBootVersion:

@Component
public class SpringBootVersionInfoContributor implements InfoContributor {
    @Override
    public void contribute(Info.Builder builder) {
        builder.withDetail("spring-boot.version", SpringBootVersion.getVersion());
    }
}

This seems a pretty solid idiomatic approach to adding this detail.

Soutor answered 18/12, 2021 at 3:37 Comment(0)
L
0

You can use the parent version property: [email protected]@

Resource filtering should be enabled by default by spring-boot-starter-parent, but since you mentioned the placeholder didn't get replaced, you can configure the resources plugin manually. From the plugin docs:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <configuration>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </configuration>
</plugin>
Legaspi answered 10/4 at 11:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.