Skip to content
Advertisement

Spring Boot Actuator – Get your own /info data

Is there a way to get your own /info response from the service?

I am having one service that is exposed to frontend and I would like to aggregate /info responses from all of the internal services, and also add my own.

However, the only option to get my own data is to call myself … And I would like to avoid that unnecessary HTTP call to my own service.

Can I somehow dig that information from some kind of actuator bean?

Advertisement

Answer

If you have info endpoint enabled you can simply autowire (or obtain from the context) InfoEndpoint which will be created by InfoEndpointAutoConfiguration and call it’s info method :

@Service
class Svc {

    private static final Logger LOG = LoggerFactory.getLogger(Svc.class);
    private InfoEndpoint infoEndpoint;

    Svc(final InfoEndpoint infoEndpoint) {
        this.infoEndpoint = infoEndpoint;
    }
    
    void perform() {
        LOG.info("{}", infoEndpoint.info());
    }

}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement