一、 spring骨架生成 -- spring initializr
可以生成Maven、Gradle,可以自由選擇依賴,自由輸入或者通過 “switch to the full version”選擇,選擇完成後,單擊“generate Project ” 生成spring boot框架。在本次學習中採用了 maven project進行框架生成。
二、pom.xml 解讀
1、自動生成的框架通過 將 spring-boot-starter-parent 作爲parent自動引入了 spring-boot-dependencies,並進行了自動配置srping-boot-maven-plugin。
2、非自動生成的框架可以自行配置panrent。
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
三 actuator 健康檢查、審計、統計、監控。只有health、info通過http暴露了出來。
Endpoint ID | Description |
---|---|
auditevents | 顯示應用暴露的審計事件 (比如認證進入、訂單失敗) |
info | 顯示應用的基本信息 |
health | 顯示應用的健康狀態 |
metrics | 顯示應用多樣的度量信息 |
loggers | 顯示和修改配置的loggers |
logfile | 返回log file中的內容(如果logging.file或者logging.path被設置) |
httptrace | 顯示HTTP足跡,最近100個HTTP request/repsponse |
env | 顯示當前的環境特性 |
flyway | 顯示數據庫遷移路徑的詳細信息 |
liquidbase | 顯示Liquibase 數據庫遷移的纖細信息 |
shutdown | 讓你逐步關閉應用 |
mappings | 顯示所有的@RequestMapping路徑 |
scheduledtasks | 顯示應用中的調度任務 |
threaddump | 執行一個線程dump |
heapdump | 返回一個GZip壓縮的JVM堆dump |
2、打開/關閉 actuator 方法
在application.properties 中配置 management.endpoint.shutdowm.enabled = true
3、暴露 actuator
默認,actuator endpoint通過JMX被暴露,而通過HTTP暴露的只有health
和info
。
以下是你可以通過應用的properties可以通過HTTP和JMX暴露的actuator endpoint。
-
通過HTTP暴露Actuator endpoints。
# Use "*" to expose all endpoints, or a comma-separated list to expose selected ones management.endpoints.web.exposure.include=health,info management.endpoints.web.exposure.exclude=
-
通過JMX暴露Actuator endpoints。
# Use "*" to expose all endpoints, or a comma-separated list to expose selected ones management.endpoints.jmx.exposure.include=* management.endpoints.jmx.exposure.exclude=