简体   繁体   中英

spring boot actuator endpoint mapping root class

In spring we can design rest web service like below.

@RestController
public class HelloController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello");
        return "hello";
    }
}

When we do so, @RestController & @RequestMapping will internally manage request mapping part. So when I will hit url ie http://localhost:8080/hello it will point to printWelcome method.

I was looking into spring boot actuator source code. If we will use spring boot actuator in our application it will provide us some endpoints, which has exposed as rest APIs like health, metrics, info. So in my application if I am using spring boot actuator, when I will hit the url like "localhost:8080/health" I will get response.

So now my question is in spring boot actuator source code where this URLs get mapped. I have debugged source code of spring boot actuator, but not able to find out the root class of mapping of endpoints.

Can anyone please help ?

here it is , In AbstractEndpoint it says

/**
     * Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped
     * to a URL (e.g. 'foo' is mapped to '/foo').
     */

If you see HealthEndPoint it extends AbstractEndpoint and does a super("health", false); , thats where it maps to "localhost:8080/health".

All spring-boot-actuator endpoints extends AbstractEndpoint (In Health endpoint case for example: class HealthEndpoint extends AbstractEndpoint<Health> ) which construcor has the id of the Endpoint.

 /**
 * Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped
 * to a URL (e.g. 'foo' is mapped to '/foo').
 */
private String id;

Otherwise, it has an invoke method (from interface Endpoint) through it is invoked the endpoint.

/**
 * Called to invoke the endpoint.
 * @return the results of the invocation
 */
T invoke();

Finally, this endpoints are configured in the class EndpointAutoConfiguration as Bean :

@Bean
@ConditionalOnMissingBean
public HealthEndpoint healthEndpoint() {
    return new HealthEndpoint(this.healthAggregator, this.healthIndicators);
}

Take a look this post where explains how to custom your endpoint:

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