Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add things to the /info endpoint in spring boot programmatically?

Tags:

How do I add things to the /info endpoint in Spring Boot programmatically? The documentation states that this is possible for the /health endpoint through the use of HealthIndicator interface. Is there something for the /info endpoint as well?

I would like to add operating system name and version and other runtime info there.

like image 571
Wim Deblauwe Avatar asked May 26 '14 06:05

Wim Deblauwe


People also ask

How do I add endpoints in Spring boot?

Mapping Endpoints In a Spring Boot application, we expose a REST API endpoint by using the @RequestMapping annotation in the controller class. For getting these endpoints, there are three options: an event listener, Spring Boot Actuator, or the Swagger library.

How can data exposed by the info endpoint be customized?

Endpoints can be customized using Spring properties. You can change if an endpoint is enabled , if it is considered sensitive and even its id . For example, here is an application. properties that changes the sensitivity and id of the beans endpoint and also enables shutdown .

How do I add an actuator dependency?

To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.


1 Answers

In Spring Boot 1.4, you are able to declare InfoContributer beans to make this a whole lot easier:

@Component public class ExampleInfoContributor implements InfoContributor {      @Override     public void contribute(Info.Builder builder) {         builder.withDetail("example",                 Collections.singletonMap("key", "value"));     }  } 

See http://docs.spring.io/spring-boot/docs/1.4.0.RELEASE/reference/htmlsingle/#production-ready-application-info-custom for more info.

like image 184
Wim Deblauwe Avatar answered Sep 18 '22 03:09

Wim Deblauwe