Java spring引导执行器端点映射根类

Java spring引导执行器端点映射根类,java,spring,spring-boot,spring-boot-actuator,Java,Spring,Spring Boot,Spring Boot Actuator,在春季,我们可以像下面这样设计RESTWeb服务 @RestController public class HelloController { @RequestMapping(value = "/hello", method = RequestMethod.GET) public String printWelcome(ModelMap model) { model.addAttribute("message", "Hello"); return

在春季,我们可以像下面这样设计RESTWeb服务

@RestController
public class HelloController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello");
        return "hello";
    }
}
当我们这样做时,@RestController&@RequestMapping将在内部管理请求映射部分。所以当我点击url时,它会指向printWelcome方法

我正在研究spring启动执行器的源代码。如果我们在应用程序中使用SpringBootActuator,它将为我们提供一些端点,这些端点已公开为RESTAPI,如health、metrics和info。因此,在我的应用程序中,如果我使用spring引导执行器,当我点击“localhost:8080/health”这样的url时,我将得到响应

现在我的问题是spring启动执行器源代码中的URL映射。我已经调试了spring启动执行器的源代码,但无法找到端点映射的根类

有人能帮忙吗?

是的,抽象地说

/**
     * Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped
     * to a URL (e.g. 'foo' is mapped to '/foo').
     */
如果您看到它扩展了AbstractEndpoint并执行了一个
super(“health”,false),这就是它映射到“localhost:8080/health”的地方

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

如果您看到它扩展了AbstractEndpoint并执行了一个
super(“health”,false),这是它映射到“localhost:8080/health”的地方。

所有spring启动执行器端点都扩展了AbstractEndpoint(在健康端点的情况下,例如:
类HealthEndpoint扩展了AbstractEndpoint
),construcor具有端点的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;
否则,它有一个调用方法(从接口端点),通过它调用端点

/**
 * Called to invoke the endpoint.
 * @return the results of the invocation
 */
T invoke();
最后,该端点在类
EndpointAutoConfiguration
中配置为
Bean

@Bean
@ConditionalOnMissingBean
public HealthEndpoint healthEndpoint() {
    return new HealthEndpoint(this.healthAggregator, this.healthIndicators);
}
看看这篇文章,其中解释了如何自定义端点:


所有spring启动执行器端点都扩展了AbstractEndpoint(在健康端点的情况下,例如:
类健康端点扩展了AbstractEndpoint
),construcor具有端点的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;
否则,它有一个调用方法(从接口端点),通过它调用端点

/**
 * Called to invoke the endpoint.
 * @return the results of the invocation
 */
T invoke();
最后,该端点在类
EndpointAutoConfiguration
中配置为
Bean

@Bean
@ConditionalOnMissingBean
public HealthEndpoint healthEndpoint() {
    return new HealthEndpoint(this.healthAggregator, this.healthIndicators);
}
看看这篇文章,其中解释了如何自定义端点: