liveBook · Manning

InfoContributor

As explained in Spring in Action, Sixth Edition

A Spring Boot Actuator interface whose implementations contribute information to an application's info endpoint response.

InfoContributor lets a Spring Boot Actuator application add dynamic information to the /info endpoint. Unlike static info.* properties, an implementation can query application data and publish the result. section 15.3.1

Publishing taco statistics

Create a component that implements InfoContributor and injects TacoRepository. Its contribute() method reads the repository count, places it in a map, and passes that map to the builder with the label taco-stats. A reactive repository returns Mono<Long>, so the example calls block() before publishing the count. 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);
  }
}

Use the complete listing to see the implementation, constructor injection, @Component registration, repository query, and withDetail() call together. section 15.3.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines the interface and demonstrates one repository-backed implementation, but does not detail the interface internals.
Examples
Uses TacoRepository to expose a taco count under a taco-stats response object.
What it assumes
Assumes an enabled /info endpoint and a TacoRepository; introduces InfoContributor and its contribute() contract through implementation.
What you can do after
Build a custom contributor that queries application data and publishes structured details through /info.
How it connects
Connects Spring Boot Actuator, the /info endpoint, reactive repositories, and static info.* properties.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.