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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With