简体   繁体   English

spring boot 执行器端点映射根类

[英]spring boot actuator endpoint mapping root class

In spring we can design rest web service like below.在 spring 中,我们可以设计如下所示的休息 Web 服务。

@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.当我们这样做时,@RestController & @RequestMapping 将在内部管理请求映射部分。 So when I will hit url ie http://localhost:8080/hello it will point to printWelcome method.因此,当我点击 url 即http://localhost:8080/hello 时,它将指向 printWelcome 方法。

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.如果我们将在我们的应用程序中使用 Spring Boot 执行器,它将为我们提供一些端点,这些端点已作为健康、指标、信息等其他 API 公开。 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.因此,在我的应用程序中,如果我使用的是 Spring Boot 执行器,当我点击“localhost:8080/health”这样的 url 时,我会得到响应。

So now my question is in spring boot actuator source code where this URLs get mapped.所以现在我的问题是在这个 URL 被映射的 Spring Boot 执行器源代码中。 I have debugged source code of spring boot actuator, but not able to find out the root class of mapping of endpoints.我已经调试了spring boot执行器的源代码,但无法找到端点映射的根类。

Can anyone please help ?任何人都可以帮忙吗?

here it is , In AbstractEndpoint it says 在这里,在 AbstractEndpoint 它说

/**
     * 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);如果您看到HealthEndPoint,它会扩展 AbstractEndpoint 并执行super("health", false); , thats where it maps to "localhost:8080/health". ,这就是它映射到“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.所有 spring-boot-actuator 端点都扩展了 AbstractEndpoint (在 Health 端点案例中,例如: class HealthEndpoint extends AbstractEndpoint<Health> )其构造函数具有端点的 id。

 /**
 * 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.否则,它有一个 invoke 方法(来自接口 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 :最后,这个端点在EndpointAutoConfiguration类中配置为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:看看这篇文章,其中解释了如何自定义您的端点:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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