执行器提供的主要功能 运行状况检查:您可以使用运行状况端点来检查正在运行的应用程序的状态。 通过HTTP / JMX进行监视和管理:Actuator支持HTTP端点以及Java管理扩展(JMX),以提供监视和管理应用程序的标准机制。
将执行器启用到Spring Boot项目中 您可以通过包含以下依赖项将Actuator启用到Spring引导项目中。
//Gradle org.springframework.boot:spring-boot-starter-actuator:2.3.1.RELEASE //Maven <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.3.1.RELEASE</version> </dependency>
执行器提供的端点报价 默认情况下,“健康”和“信息”端点已启用
默认的公开端点。 其他端点是敏感的,不建议在没有安全性的情况下暴露于生产环境。在演示时,让我们公开所有API。
management.endpoints.web.exposure.include=*
包括和排除端点。
您甚至可以通过定义以下属性来包含或排除端点
# wild card to include/exclude all management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=* # you can include specific properties like below management.endpoints.web.exposure.include=env,beans management.endpoints.web.exposure.exclude=heapdump
自定义管理服务器地址 您可以自定义管理服务器端口,这将帮助您定义端口的有限范围。
management.server.port=8081 management.server.address=127.0.0.1
management.server.port=8081
management.server.address=127.0.0.1
公开自定义端点
带有@ReadOperation,@WriteOperation或注释的任何方法都会@DeleteOperation通过JMX和HTTP自动公开。甚至您也可以使用@JmxEndpoint或公开特定于技术的终结点@WebEndpoint。
@ReadOperation
@WriteOperation
@DeleteOperation
@JmxEndpoint
@WebEndpoint
在这里,我为您分享使用Spring Boot 2.x公开端点的示例
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.stereotype.Component; @Component @org.springframework.boot.actuate.endpoint.annotation.Endpoint(id = "say-hello") public class Endpoint { @ReadOperation public String sayHello() { return "Hello World"; } }
简介:弹簧启动执行器是您可以在应用程序中添加的最佳库之一,从而可以更轻松地启用可用于生产的功能。它提供了可以在日常生产支持中使用的关键功能。
原文链接:http://codingdict.com