您好,欢迎访问一九零五行业门户网

SpringBoot2怎么自定义端点

springboot2新特性 自定义端点package com.yan.otlan.springboot; import org.springframework.boot.actuate.endpoint.annotation.endpoint;import org.springframework.boot.actuate.endpoint.annotation.readoperation;import org.springframework.boot.actuate.endpoint.annotation.selector;import org.springframework.stereotype.component; @endpoint(id = "custompoint")@componentpublic class statusendpoint { @readoperation public string getcustom(@selector string name) { return "myname is ." + name; } }
只需要三个注解 @endpoint、@readoperation、@selector
启动springboot项目
看到红色mapped就说明可以成功了
访问http://127.0.0.1:8080/actuator/custompoint/156
结果
springboot-actuator-自定义端点属性关闭所有端点management.endpoints.enabled-by-default: false
修改访问项目路径默认访问路径为/actuator,可通过修改以下属性进行修改
management.endpoints.web.base-path: /actuator
如默认访问路径为 http://ip:port/actuator
如想将访问路径修改为 http://ip:port/myactuator
可将属性设置为 /myactuator
路径必须以/开始,否则无法访问
以上就是springboot2怎么自定义端点的详细内容。
其它类似信息

推荐信息