[英]Spring Boot Actuator - Custom Endpoints
我在我的项目中使用Spring Boot Actuator
模块,它公开了 REST 端点 URL 来监视和管理生产环境中的应用程序使用情况,而无需对其中任何一个进行编码和配置。
默认情况下,仅公开/health
和/info
端点。
我正在根据我的用例通过application.properties
文件自定义端点。
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
我想了解,Spring Boot 究竟在哪里为/health
和/info
创建实际端点,它如何通过 HTTP 公开它们?
感谢@Puce 和@MarkBramnik 帮助我参考文档和代码存储库。
我想了解端点是如何工作的,以及它们是如何通过 HTTP 暴露的,以便我可以创建自定义端点以在我的应用程序中使用。
Spring 框架的一大特点是它很容易扩展,我也能做到这一点。
要创建自定义执行器端点,请在 class 上使用 @Endpoint 注释。 然后利用方法上的@ReadOperation
/ @WriteOperation
/ @DeleteOperation
注释,根据需要将它们公开为执行器端点 bean。
参考文档: 实现自定义端点
参考示例:
@Endpoint(id="custom_endpoint")
@Component
public class MyCustomEndpoint {
@ReadOperation
@Bean
public String greet() {
return "Hello from custom endpoint";
}
}
端点 id 即 custom_endpoint 需要在要启用的执行器端点列表中进行配置。
application.properties
:
management.endpoints.web.exposure.include=health,info,custom_endpoint
重新启动后,端点就像一个魅力!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.