简体   繁体   中英

Spring Boot Actuator - Custom Endpoints

I am using Spring Boot Actuator module in my project which exposes REST endpoint URLs to monitor & manage application usages in production environment, without coding & configuration for any of them.

By default, only /health and /info endpoints are exposed.

I am customising the endpoints via application.properties file as per my use case.

application.properties.

#To expose all endpoints
management.endpoints.web.exposure.include=*
 
#To expose only selected endpoints
management.endpoints.jmx.exposure.include=health,info,env,beans

I want to understand, where exactly does Spring Boot create actual endpoints for /health and /info and how does it expose them over HTTP?

Thanks @Puce and @MarkBramnik for helping me out with the reference docs & code repository.

I wanted to understand how the endpoints were working and how they were exposed over HTTP, so that I could create custom endpoints to leverage in my application.

One of the great features of Spring Framework is that it's very easy to extend, and I was able to achieve the same.

To create a custom actuator endpoints, Use @Endpoint annotation on a class. Then leverage @ReadOperation / @WriteOperation / @DeleteOperation annotations on the methods to expose them as actuator endpoint bean as needed.

Reference Doc: Implementing Custom Endpoints

Reference Example:

@Endpoint(id="custom_endpoint")
@Component
public class MyCustomEndpoint {

    @ReadOperation
    @Bean
    public String greet() {
        return "Hello from custom endpoint";
    }
}

The endpoint id ie custom_endpoint needs to be configured in the list of actuator endpoints to be enabled.

application.properties :

management.endpoints.web.exposure.include=health,info,custom_endpoint

After a restart, endpoint works like a charm!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM