Spring Boot的Actuator在应用程序中提供众多Web端点,我们可以通过它们了解应用程序允许的状态,也可以通过提供的rest接口可以获取整个依赖于spring体系中bean如何组装在一起,也可以掌握应用程序允许的环境属性消息等
如何启用Actuator的端点,只需要在项目中引入Actuator的依赖:
在Maven中构建 :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
其中springboot2.x版本与spirngboot1.5x构建有很大不同
springboot2.x:
@Endpoint(id = "dtc-refresh"):@Endpoint设置为端点类id设置端点访问路径
@WriteOperation:类比于post请求作用
@DeleteOperation:类比于delete请求作用
@ReadOperation:类比于get请求作用
@Selector:接收请求参数
第一步定义端点类:
@Endpoint(id = "test")
public class TestEndpoint{
/**
*test
*/
@WriteOperation
public void test1() {
//编写代码
}
}
@ReadOperation
public void test2(@Selector String type) {
//
}
2将端点注入到spring中(使用@Componen注解或使用@bean)
3:在2.x系列 actuator默认只会开启info,health,如果需要开启所有端点访问(不开启反问会404):
###springboot2.x Actuator只暴露了health和info端点
##如果需要则使用下面配置
management:
endpoints:
web:
exposure:
include: "*"
4:最终访问http://localhost:8866/actuator/test