The Spring Boot Actuator info endpoint answers a basic question about a running application: what is it? Send a GET request to /actuator/info to see its information as JSON. An unconfigured response may be just {}. Unlike the health endpoint, which reports how the application is doing, the info endpoint is a place to publish details you choose. section 15.2.1
info:
contact:
email: support@tacocloud.com
phone: 822-625-6831
Add these properties to application.yml to publish support contact details. Their names have no special meaning beyond the info prefix; the response nests email and phone under contact. section 15.2.1
Properties work well for values you can configure ahead of time. For information that must be calculated, implement Spring Boot’s InfoContributor interface. Its contribute() method receives a Builder; call withDetail() to add a named piece of information to the response. section 15.3.1
Listing 15.3 A custom implementation of InfoContributor
package tacos.actuator;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.info.Info.Builder;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
import tacos.data.TacoRepository;
@Component
public class TacoCountInfoContributor implements InfoContributor {
private TacoRepository tacoRepo;
public TacoCountInfoContributor(TacoRepository tacoRepo) {
this.tacoRepo = tacoRepo;
}
@Override
public void contribute(Builder builder) {
long tacoCount = tacoRepo.count().block();
Map<String, Object> tacoMap = new HashMap<String, Object>();
tacoMap.put("count", tacoCount);
builder.withDetail("taco-stats", tacoMap);
}
}
This @Component injects a repository, obtains its count, and publishes it under taco-stats. The repository is reactive, so the example calls block() to obtain the value from its Mono<Long>; the resulting JSON contains taco-stats.count. section 15.3.1
The endpoint can also identify the build and source revision:
- Configure the Spring Boot Maven plugin’s build-info goal or Gradle’s springBoot { buildInfo() }. The illustrated build response includes the artifact, name, time, version, and group. section 15.3.1
- Use the illustrated Maven Git commit ID plugin or Gradle Git properties plugin to supply Git information such as branch, commit ID, and commit time. Setting management.info.git.mode to full exposes more commit details than the shorter response. section 15.3.1
Once available, the same information can appear in Spring Boot Admin’s Details screen alongside application health. Decide what to expose before using the endpoint operationally: Actuator web endpoints can be selectively exposed and secured with Spring Security, and full Git details can include a committer’s name and email. section 16.2.1 section 15.5
