SpringBoot自定义Endpoint
文章目录
pom依赖
pom.xml中加入如下依赖
1 2 3 4 |
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> |
编写自定义Endpoint
1 2 3 4 5 6 7 8 9 10 11 |
@Configuration @Endpoint(id = "my-endpoint") public class MyEndpoint { @ReadOperation public Map<String, Object> endpoint() { Map<String, Object> map = new HashMap<>(16); map.put("message", "this is my endpoint"); return map; } } |
配置
1
|
management.endpoints.web.exposure.include=my-endpoint |
说明
- @EndPoint中的id不能使用驼峰法,需要以-分割
- @Spring Boot会自动扫描@EndPoint注解
- 方法上的@ReadOperation, @WriteOperation, @DeleteOperation注解,分别对应生成Get/Post/Delete的Mapping。注解中的produces参数,可以指定media type, 如:application/json等。
文章作者 binbin wen
上次更新 2020-09-02