SpringBoot2.0學習筆記 使用Actualor監控專案執行狀態
阿新 • • 發佈:2019-02-14
SpringBoot的一大特性就是開發者可以通過它其中的Actualor元件檢視專案的執行狀態
在SpringBoot2.0推出之後,Actualor的配置資訊發生了一些變化,與之前的版本有所不同,本文就針對SpringBoot2.0對Actualor的使用做簡單的說明.
加入依賴
<!-- actuator監控包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
配置資訊
#actuator埠設定,不配置則採用專案預設埠 management.server.port=8090 #修改訪問路徑,SpringBoot2.0預設是 /actuator 可以通過這個屬性值修改訪問路徑 management.endpoints.web.base-path=/manager #開放所有查詢功能 預設只開啟了health、info兩個功能 management.endpoints.web.exposure.include=* #顯示健康詳細資訊 預設不顯示詳細資訊 management.endpoint.health.show-details=always
監控功能API舉例
只需在/actualor(或你已經更改的路徑)後加入你想要檢視的資訊的路徑,就可以檢視到相應的資訊了.
注:/info需要自己在SpringBoot檔案中進行配置才會顯示
例如: [email protected]
info.contact.phone=123456789
並且/shutdown需要在配置檔案中手動開啟開關才可以使用
endpoints.shutdown.enabled=true
之後執行專案,然後進行測試
檢視到了相應的資訊,大功告成.