這是我參與8月更文挑戰的第5天,活動詳情查看:8月更文挑戰
有些地方描述爲四大組件,有些地方描述爲四大核心原理,有些地方描述爲四大神器。我的認爲稱呼神器更爲合適。如今描述Actuator監控管理、Spring Boot CLI 命令行工具。java
Actuator 是 Spring Boot 的一個很是強大的功能。它能夠實現應用程序的監控管理,好比幫助咱們收集應用程序的運行狀況、監測應用程序的健康情況以及顯示HTTP跟蹤請求信息等。它是咱們搭建微服務架構必不可少的環節,是整個系統穩定運行的保障。web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
複製代碼
Actuator 內置有不少端點(endpoint),咱們經過這些端點能夠得到不一樣的監控信息。但Actautor默認只開啓health和info兩個端點,須要對application.yml文件進行配置:spring
management:
endpoints:
web:
exposure:
include: '*'
複製代碼
其中'*'
標識開啓全部端點。
也能夠開啓指定端點:json
management:
endpoints:
web:
exposure:
include: health,info,httptrace
複製代碼
上述配置表示開啓health、info、httptrace端點。此時啓動程序訪問http://localhost:8080/actuator/health ,會看到以下結果。springboot
{"status":"UP"}
複製代碼
UP說明當前系統正常運行。markdown
Spring Boot CLI(Command Line Interface)是一款用於快速搭建基於Spring原型的命令行工具。它支持運行Groovy腳本,這意味着你能夠擁有一個與Java語言相似的沒有太多樣板代碼的語法。經過CLI來使用Spring Boot不是惟一方式,但它是讓Spring應用程序搭建的最快速方式。架構
下載地址
repo.spring.io/release/org…
配置環境變量app
若是對Groovy不熟悉,能夠直接編寫java的Controller。spring-boot
@RestController
public class AdviceController {
@RequestMapping("/")
public String hello(){
return "hello world!"
}
}
複製代碼