日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot Endpoint

發布時間:2024/1/1 javascript 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot Endpoint 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

介紹

SpringBoot的Endpoint主要是用來監控應用服務的運行狀況,并集成在Mvc中提供查看接口。內置的Endpoint比如HealthEndpoint會監控dist和db的狀況,MetricsEndpoint則會監控內存和gc的狀況。

Endpoint的接口如下,其中invoke()是主要的方法,用于返回監控的內容,isSensitive()用于權限控制。

public interface Endpoint<T> {String getId();boolean isEnabled();boolean isSensitive();T invoke(); }

Endpoint的加載還是依靠spring.factories實現的。spring-boot-actuator包下的META-INF/spring.factories配置了EndpointAutoConfiguration.

自定義Endpoint

以監控內存為例

定義內存實體類

public class MemoInfo {private long maxMemo;public long getMaxMemo() {return maxMemo;}public void setMaxMemo(long maxMemo) {this.maxMemo = maxMemo;} }

編寫Endpoint類

import org.springframework.boot.actuate.endpoint.Endpoint; public class MyEndpoint implements Endpoint<MemoInfo> {public String getId() {return "myendpoint";}public MemoInfo invoke() {MemoInfo memInfo = new MemoInfo(); Runtime runtime = Runtime.getRuntime(); memInfo.setMaxMemo(runtime.maxMemory());return memInfo;}public boolean isEnabled() {return true;}public boolean isSensitive() {return false;} }

getId()是Endpoint唯一的標識,另外也是MVC接口對外暴露的路徑,以上代碼對外訪問路徑就是:http://localhost:8080/myendpoint。

編寫配置類

import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;@Configuration public class MyEndPointAutoConfig {@Beanpublic MyEndpoint myEndPoint() { return new MyEndpoint(); } }

總結

以上是生活随笔為你收集整理的SpringBoot Endpoint的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。