按網友的方法添加依賴和配置屬性後, 仍然無法訪問.最後發現是導入的依賴問題.
我導入的是spring-boot-actuator(此依賴在maven庫中能找到, 所以這問題比較隱蔽).
而正確的依賴是 spring-boot-starter-actuator. 在此寫給和我一樣粗心的小夥伴們.
學習actuator的參考文章: https://blog.csdn.net/m0_37809146/article/details/86686067
1) 添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. 配置屬性
management:
endpoints:
web:
exposure:
# 這裏用* 代表暴露所有端點只是爲了觀察效果,實際中按照需進行端點暴露
include: "*"
endpoint:
health:
# 詳細信息顯示給所有用戶。
show-details: always
health:
status:
http-mapping:
# 自定義健康檢查返回狀態碼對應的http狀態碼
FATAL: 503