gpt4 book ai didi

java - Spring Boot执行器端点映射根类

转载 作者:行者123 更新时间:2023-12-02 03:19:49 25 4
gpt4 key购买 nike

在 Spring 中,我们可以设计如下所示的 REST Web 服务。

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

当我们这样做时,@RestController & @RequestMapping 将在内部管理请求映射部分。所以当我点击网址时,即 http://localhost:8080/hello它将指向 printWelcome 方法。

我正在研究 Spring Boot 执行器源代码。如果我们在应用程序中使用 Spring Boot Actuator,它将为我们提供一些端点,这些端点已作为剩余 API 公开,例如运行状况、指标、信息。因此,在我的应用程序中,如果我使用 Spring Boot Actuator,当我点击“localhost:8080/health”之类的 url 时,我会得到响应。

所以现在我的问题是在 Spring Boot 执行器源代码中映射此 URL。我已经调试了Spring Boot Actuator的源代码,但无法找到端点映射的根类。

有人可以帮忙吗?

最佳答案

here是的,在 AbstractEndpoint 中它说

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

如果您看到 HealthEndPoint它扩展了 AbstractEndpoint 并执行 super("health", false); ,这就是它映射到“localhost:8080/health”的位置。

关于java - Spring Boot执行器端点映射根类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39766522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com